/** * Fixes table th scope errors * @param string $error_html - The color(s) that need to be replaced * @param string $new_content - The new CSS color(s) from the user * @param bool $submitting_again - If the user is resubmitting their error fix * @return string $fixed_ths - The html with corrected th scopes */ public function fixTableThScopes($error_html, $new_content, $submitting_again = false) { $this->dom->loadHTML('<?xml encoding="utf-8" ?>' . $error_html); $ths = $this->dom->getElementsByTagName('th'); foreach ($ths as $th) { $th->setAttribute('scope', $new_content); $fixed_th = $this->dom->saveHTML($th); } return $fixed_th; }
/** * Constructor for a response message * * @param object $node A dom document node. */ function __construct($node = null) { if (isset($node)) { foreach (get_class_vars('Services_W3C_HTMLValidator_Message') as $var => $val) { $element = $node->getElementsByTagName($var); if ($element->length) { $this->{$var} = $element->item(0)->nodeValue; } } } }
/** * pSimpleGetValue * Extrai o valor do node DOM * * @param object $theObj Instancia de DOMDocument ou DOMElement * @param string $keyName identificador da TAG do xml * @param string $extraTextBefore prefixo do retorno * @param string extraTextAfter sufixo do retorno * @param number itemNum numero do item a ser retornado * @return string */ protected function pSimpleGetValue($theObj, $keyName, $extraTextBefore = '', $extraTextAfter = '', $itemNum = 0) { if (empty($theObj)) { return ''; } //if (!($theObj instanceof DOMDocument) && !($theObj instanceof DOMElement)) { // throw new nfephpException( // "Metodo CommonNFePHP::pSimpleGetValue() " // . "com parametro do objeto invalido, verifique!" // ); //} $vct = $theObj->getElementsByTagName($keyName)->item($itemNum); if (isset($vct)) { return $extraTextBefore . trim($vct->nodeValue) . $extraTextAfter; } return ''; }
/** * Gets all controllers in the layout file. If a sector is specified * then get only those attached to that sector. * * @param string $inSector * @return array */ public function getControllers($inSector = null) { if (empty($this->controllers)) { $cacheKey = 'layout_cntrlrs_' . $this->name; if (($this->controllers = $this->_cache->get($cacheKey)) == false) { $this->controllers = array(); foreach ($this->dom->getElementsByTagName('controller') as $node) { // Gather all configuration values $config = array('displayTitle' => true, 'customTitle' => null, 'htmlWrapClass' => null); foreach ($node->getElementsByTagName('config')->item(0)->childNodes as $confNode) { $config[$confNode->nodeName] = $confNode->nodeValue; } // 2.3.51 changed attr 'for_sector' into 'sector', use older if exists if (($sector = $node->getAttribute('for_sector')) == false) { $sector = $node->getAttribute('sector'); } // Store the controllers $cid = $node->getAttribute('id'); $this->controllers[$cid] = array('id' => $cid, 'order' => (int) $node->getAttribute('order'), 'sector' => strtoupper($sector), 'mod' => $node->getElementsByTagName('mod')->item(0)->nodeValue, 'con' => $node->getElementsByTagName('con')->item(0)->nodeValue, 'sec' => $node->getElementsByTagName('sec')->item(0)->nodeValue, 'config' => $config); } // Normalize, order and cache the controllers zula_normalize($this->controllers); uasort($this->controllers, array($this, 'orderControllers')); $this->_cache->add($cacheKey, $this->controllers); } } if ($inSector == null) { return $this->controllers; } else { $inSector = strtoupper($inSector); $controllers = array(); foreach ($this->controllers as $cntrlr) { if ($cntrlr['sector'] == $inSector) { $controllers[$cntrlr['id']] = $cntrlr; } } return $controllers; } }
/** * Loads the html body and sends it to the parsing loop to convert all * DOM nodes to BBC */ public function get_bbc() { // For this html node, find all child elements and convert $body = $this->_parser ? $this->doc->getElementsByTagName('body')->item(0) : $this->doc->root; // Convert all the nodes that we know how to $this->_convert_childNodes($body); // Done replacing HTML elements, now get the converted DOM tree back into a string $bbc = $this->_parser ? $this->doc->saveHTML() : $this->doc->save(); $bbc = $this->_recursive_decode($bbc); if ($this->_parser) { // Using the internal DOM methods we need to do a little extra work $bbc = html_entity_decode(htmlspecialchars_decode($bbc, ENT_QUOTES)); if (preg_match('~<body>(.*)</body>~s', $bbc, $body)) { $bbc = $body[1]; } } // Remove comment blocks $bbc = preg_replace('~\\<\\!--.*?-->~i', '', $bbc); $bbc = preg_replace('~\\<\\!\\[CDATA\\[.*?\\]\\]\\>~i', '', $bbc); // Remove non breakable spaces that may be hiding in here $bbc = str_replace(" ", ' ', $bbc); $bbc = str_replace(" ", ' ', $bbc); // Strip any excess leading/trailing blank lines we may have produced O:-) $bbc = trim($bbc); $bbc = preg_replace('~^(?:\\[br\\s*\\/?\\]\\s*)+~', '', $bbc); $bbc = preg_replace('~(?:\\[br\\s*\\/?\\]\\s*)+$~', '', $bbc); $bbc = str_replace('[hr][br]', '[hr]', $bbc); // Remove any html tags we left behind ( outside of code tags that is ) $parts = preg_split('~(\\[/code\\]|\\[code(?:=[^\\]]+)?\\])~i', $bbc, -1, PREG_SPLIT_DELIM_CAPTURE); for ($i = 0, $n = count($parts); $i < $n; $i++) { if ($i % 4 == 0) { $parts[$i] = strip_tags($parts[$i]); } } $bbc = implode('', $parts); return $bbc; }
/** * * @param type $limit * @param string $Path * @return type */ public function path($limit = 1, $Path = '') { /** First Validation **/ if (!trim($this->node)) { return array(); } $this->dom = new DOMDocument(); if ($this->path) { $this->dom->load($this->path); } elseif ($this->string) { $this->dom = new DOMDocument(); @$this->dom->loadXML($this->string); } /** reset values array **/ $this->values = array(); $categories = $this->dom->getElementsByTagName($this->node); $tree = array(); if (!trim($Path)) { $Path = '/' . $this->node . '/'; } for ($i = 0; $i < $categories->length; $i++) { if ($i >= $limit) { break; } $cat = $categories->item($i); $childs = array(); foreach ($cat->childNodes as $child) { if ($child->nodeType == XML_TEXT_NODE) { continue; } $childs[$Path . $child->nodeName . '/'] = $this->childs($child, $Path . $child->nodeName . '/'); } $tree[$i] = $childs; } return $tree; }
/** * * @param string $psTag * @param object $poObject * @return object|NULL */ public function xmlByTagName($psTag, &$poObject = null) { if ($poObject == null) { $poObject =& $this->coDocument; } if ($this->cbLoadOK) { $loList = $poObject->getElementsByTagName($psTag); if (is_object($loList) && $loList->length != 0) { return $loList; } else { return null; } } }
/** * Returns powerpoint head title of a pptx based on its document object * * @param object $dom a document object to extract a title from. * @return string a title of the page * */ static function title($dom) { $coreProperties = $dom->getElementsByTagName("coreProperties"); $property = $coreProperties->item(0); $title = ""; if ($property) { $titles = $property->getElementsByTagName("title"); if ($titles->item(0)) { $title = $titles->item(0)->nodeValue; } } return $title; }
/** * Read data from a string, and return a list of features. * @return array of Feature instances */ private function _parseData() { $types = array("NetworkLink", "Link", "Style", "StyleMap", "Placemark"); foreach ($types as $type) { $nodes = $this->doc->getElementsByTagName($type); //getElementsByTagNameNS ? if ($nodes->length == 0) { continue; } // skip to next iteration // Util::log($nodes->item(0)->nodeName, 'TYPE'); switch (strtolower($type)) { // Fetch external links case "link": case "networklink": $this->_parseLinks($nodes, $options); break; // // parse style information // // parse style information case "style": if ($this->extractStyles == true) { $this->_parseStyles($nodes, $options); } break; // // case "stylemap": // if(isset($this->_extractStyles)) { // $this->_parseStyleMaps($nodes, $options); // } // break; // parse features // // case "stylemap": // if(isset($this->_extractStyles)) { // $this->_parseStyleMaps($nodes, $options); // } // break; // parse features case "placemark": $this->_parseFeatures($nodes, $options); break; } } return $this->features; }
/** * Returns number of slides of pptx based on its document object * * @param object $dom a document object to extract a title from. * @return number number of slides * */ static function numSlides($dom) { $properties = $dom->getElementsByTagName("Properties"); $property = $properties->item(0); $slides = $property->getElementsByTagName("Slides"); $number = $slides->item(0)->nodeValue; return $number; }
/** * Converts tables tags to markdown extra table syntax * * - Have to build top down vs normal inside out due to needing col numbers and widths * * @param object $node */ private function _convert_table($node) { $table_heading = $node->getElementsByTagName('th'); if ($this->_get_item($table_heading, 0) === null) { return; } $th_parent = $table_heading ? $this->_parser ? $this->_get_item($table_heading, 0)->parentNode->nodeName : $this->_get_item($table_heading, 0)->parentNode()->nodeName() : false; // Set up for a markdown table, then storm the castle $align = array(); $value = array(); $width = array(); $max = array(); $header = array(); $rows = array(); // We only markdown well formed tables ... if ($table_heading && $th_parent === 'tr') { // Find out how many columns we are dealing with $th_num = $this->_get_length($table_heading); for ($col = 0; $col < $th_num; $col++) { // Get the align and text for each th (html5 this is no longer valid) $th = $this->_get_item($table_heading, $col); $align_value = $th !== null ? strtolower($th->getAttribute('align')) : false; $align[0][$col] = $align_value === false ? 'left' : $align_value; $value[0][$col] = $this->_get_value($th); $width[0][$col] = Util::strlen($this->_get_value($th)); // Seed the max col width $max[$col] = $width[0][$col]; } // Get all of the rows $table_rows = $node->getElementsByTagName('tr'); $num_rows = $this->_get_length($table_rows); for ($row = 1; $row < $num_rows; $row++) { // Start at row 1 and get all of the td's in this row $row_data = $this->_get_item($table_rows, $row)->getElementsByTagName('td'); // Simply use the th count as the number of columns, if its not right its not markdown-able anyway for ($col = 0; $col < $th_num; $col++) { // Get the align and text for each td in this row $td = $this->_get_item($row_data, $col); $align_value = $td !== null ? strtolower($td->getAttribute('align')) : false; $align[$row][$col] = $align_value === false ? 'left' : $align_value; $value[$row][$col] = $this->_get_value($td); $width[$row][$col] = Util::strlen($this->_get_value($td)); // Keep track of the longest col cell as we go if ($width[$row][$col] > $max[$col]) { $max[$col] = $width[$row][$col]; } } } // Done collecting data, we can rebuild it, we can make it better than it was. Better...stronger...faster for ($row = 0; $row < $num_rows; $row++) { $temp = array(); for ($col = 0; $col < $th_num; $col++) { // Build the header row once if ($row === 0) { $header[] = str_repeat('-', $max[$col]); } // Build the data for each col, align/pad as needed $temp[] = $this->_align_row_content($align[$row][$col], $width[$row][$col], $value[$row][$col], $max[$col]); } // Join it all up so we have a nice looking row $rows[] = '| ' . implode(' | ', $temp) . ' |'; // Stuff in the header after the th row if ($row === 0) { $rows[] = '| ' . implode(' | ', $header) . ' | '; } } // Adjust the word wrapping since this has a table, will get mussed by email anyway $line_strlen = strlen($rows[1]) + 2; if ($line_strlen > $this->body_width) { $this->body_width = $line_strlen; } // Return what we did so it can be swapped in return implode($this->line_end, $rows); } }
/** * do all necessary changes from version 0 to version 1 */ protected function upgrade0To1() { // @see http://cometvisu.de/wiki/index.php?title=CometVisu/Update $objXPath = new DOMXPath($this->objDOM); // append namespaces to schema $this->objDOM->getElementsByTagName('pages')->item(0)->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $this->objDOM->getElementsByTagName('pages')->item(0)->setAttribute('xsi:noNamespaceSchemaLocation', '../visu_config.xsd'); // rename iframe to web $objElements = $objXPath->query('//iframe'); $i = 0; foreach ($objElements as $objElement) { $this->renameNode($objElement, 'web'); ++$i; } $this->log('renamed ' . $i . ' nodes of type \'iframe\' to \'web\''); unset($objElements, $i); // change diagram_popup to diagram $objElements = $objXPath->query('//diagram_popup'); $i = 0; foreach ($objElements as $objElement) { $objElement->setAttribute('popup', 'true'); $objElement->setAttribute('previewlabels', 'false'); $objElement->setAttribute('legend', 'popup'); $this->renameNode($objElement, 'diagram'); ++$i; } $this->log('changed ' . $i . ' nodes of type \'diagram_popup\' to \'diagram\''); unset($objElements); // change diagram_inline to diagram $objElements = $objXPath->query('//diagram_inline'); $i = 0; foreach ($objElements as $objElement) { $objElement->setAttribute('popup', 'false'); $objElement->setAttribute('previewlabels', 'true'); $objElement->setAttribute('legend', 'none'); $this->renameNode($objElement, 'diagram'); ++$i; } $this->log('changed ' . $i . ' nodes of type \'diagram_inline\' to \'diagram\''); unset($objElements); // move diagram attributes to child-nodes $objElements = $objXPath->query('//diagram|//diagram_info'); $i = 0; foreach ($objElements as $objElementNode) { if ($objElementNode->hasAttribute('rrd')) { // create rrdnode $objRRDNode = $objElementNode->ownerDocument->createElement('rrd'); $rrdContent = $objElementNode->ownerDocument->createTextNode($objElementNode->getAttribute('rrd')); $objRRDNode->appendChild($rrdContent); if ($objElementNode->hasAttribute('linecolor')) { $objRRDNode->setAttribute('color', $objElementNode->getAttribute('linecolor')); } $objElementNode->removeAttribute('rrd'); $objElementNode->appendChild($objRRDNode); } if ($objElementNode->hasAttribute('linecolor')) { $objElementNode->removeAttribute('linecolor'); } $objAxisNode = $objElementNode->ownerDocument->createElement('axis'); $addAxis = false; if ($objElementNode->hasAttribute('yaxismin')) { $objAxisNode->setAttribute('min', $objElementNode->getAttribute('yaxismin')); $objElementNode->removeAttribute('yaxismin'); $addAxis = true; } if ($objElementNode->hasAttribute('yaxismax')) { $objAxisNode->setAttribute('max', $objElementNode->getAttribute('yaxismax')); $objElementNode->removeAttribute('yaxismax'); $addAxis = true; } if ($objElementNode->hasAttribute('unit')) { $objAxisNode->setAttribute('unit', $objElementNode->getAttribute('unit')); $objElementNode->removeAttribute('unit'); $addAxis = true; } if ($addAxis) { $objElementNode->appendChild($objAxisNode); } ++$i; } $this->log('moved attributes to childs in ' . $i . ' nodes of type \'diagram(_info)\' '); unset($objElements); // remove whitespace-attributes $objAttributes = $objXPath->query('//@*[.=\' \']'); $i = 0; foreach ($objAttributes as $objAttribute) { $objAttribute->ownerElement->removeAttributeNode($objAttribute); ++$i; } $this->log('removed ' . $i . ' empty-like attributes'); // remove empty attributes $objAttributes = $objXPath->query('//@*[.=\'\']'); $i = 0; foreach ($objAttributes as $objAttribute) { $objAttribute->ownerElement->removeAttributeNode($objAttribute); ++$i; } $this->log('removed ' . $i . ' empty attributes'); // encapsulate content of 'text'-nodes in a label $objElements = $objXPath->query('//text'); $i = 0; foreach ($objElements as $objElementNode) { if ($objElementNode->getElementsByTagName('label')->length > 0) { // text-elements that already have a label-element should be left untouched! continue; } // create a new label and a new text node, append the old elements nodes to them $objLabelNode = $objElementNode->ownerDocument->createElement('label'); $objTextNode = $objElementNode->ownerDocument->createElement('text'); $objTextNode->appendChild($objLabelNode); // copy the old text-nodes' attributes tot the new one if ($objElementNode->attributes->length > 0) { foreach ($objElementNode->attributes as $objAttribute) { $objTextNode->setAttribute($objAttribute->nodeName, $objAttribute->nodeValue); } } // clone-copy all nodes to the newly created nodes if ($objElementNode->childNodes->length > 0) { foreach ($objElementNode->childNodes as $objChildNode) { // clone the node, so do not disturb the order of elements with the old parent $objNewChildNode = $objChildNode->cloneNode(true); if ($objChildNode->nodeName == 'layout') { // layout goes right into the text node $objTextNode->appendChild($objNewChildNode); } else { // all of the rest goes into the label-node $objLabelNode->appendChild($objNewChildNode); } } } // replace the old text-node with the new one $objElementNode->parentNode->replaceChild($objTextNode, $objElementNode); ++$i; } $this->log('encapsulated content of ' . $i . ' \'text\'-nodes in \'label\'-nodes'); // encapsulate content of 'diagram_'-nodes in a label $objElements = $objXPath->query('//diagram_inline[not(child::*)]|//diagram_popup[not(child::*)]'); $i = 0; foreach ($objElements as $objElementNode) { $objLabelNode = $objElementNode->ownerDocument->createElement('label'); // first, move all nodes to the childnode while (true === isset($objElementNode->firstChild)) { $objLabelNode->appendChild($objElementNode->firstChild); } $objElementNode->appendChild($objLabelNode); ++$i; } $this->log('encapsulated content of ' . $i . ' \'diagram_*\'-nodes in \'label\'-nodes'); // FROM readonly / writeonly TO disable/read/write/readwrite $objElements = $objXPath->query('//address'); $i = 0; foreach ($objElements as $objElementNode) { $boolRead = true; $boolWrite = true; if ('true' == $objElementNode->getAttribute('readonly')) { // readonly means: no write $boolWrite = false; } if ('true' == $objElementNode->getAttribute('writeonly')) { // writeonly means: no read $boolRead = false; } $objElementNode->removeAttribute('readonly'); $objElementNode->removeAttribute('writeonly'); if ($boolRead && $boolWrite) { $objElementNode->setAttribute('mode', 'readwrite'); } if ($boolRead && !$boolWrite) { $objElementNode->setAttribute('mode', 'read'); } if (!$boolRead && $boolWrite) { $objElementNode->setAttribute('mode', 'write'); } if (!$boolRead && !$boolWrite) { $objElementNode->setAttribute('mode', 'disable'); } ++$i; } $this->log('converted ' . $i . ' \'address\'-nodes from readonly/writeonly to \'mode\''); // rearrange elements based on new sequence-order $arrOrderedElements = array('page', 'group', 'text', 'switch', 'trigger', 'urltrigger', 'infotrigger', 'rgb', 'multitrigger', 'slide', 'info', 'wgplugin_info', 'image', 'imagetrigger', 'video', 'web', 'pagejump', 'colorchooser', 'diagram', 'diagram_inline', 'diagram_popup', 'diagram_info', 'rss', 'rsslog', 'strftime'); $i = 0; foreach ($arrOrderedElements as $strElementName) { $objElements = $objXPath->query('//' . $strElementName); foreach ($objElements as $objElementNode) { // sort the elements children // first, have an array of the items // do not worry: these are objects, they are references by default $arrChildNodes = array(); foreach ($objElementNode->childNodes as $objChildNode) { $arrChildNodes[] = $objChildNode; } // next: clean up the element itself foreach ($arrChildNodes as $objChildNode) { $objElementNode->removeChild($objChildNode); } // now sort $this->mergesort($arrChildNodes, array($this, 'upgrade0To1SortHelper')); // after sorting: append all children again. man, this sucks. foreach ($arrChildNodes as $objChildNode) { $objElementNode->appendChild($objChildNode); } ++$i; } } $this->log('checked and partially sorted ' . $i . ' nodes children'); }
/** * Method to build the final structure * * @return void */ public function render() { $return = ''; if ($this->render == true) { //insert the html content foreach (array_keys($this->data) as $id) { if ($this->DOM->getElementById($id) == false) { if ($id == $this->Config->template['content_div']) { throw new Exception('Cannot locate content div'); } continue; } if (isset($this->data[$id])) { $append = $this->DOM->importNode($this->data[$id]->documentElement->getElementsByTagName($this->delimiter)->item(0), true); $this->DOM->getElementById($id)->appendChild($append); } } //insert css links if (!empty($this->css)) { if ($header = $this->DOM->getElementsByTagName('head')->item(0)) { foreach ($this->css as $css) { $link = $this->DOM->createElement('link'); $link->setAttribute('type', 'text/css'); $link->setAttribute('rel', 'stylesheet'); $link->setAttribute('href', $css); $header->appendChild($link); } } } //insert js links if (!empty($this->js)) { if ($header = $this->DOM->getElementsByTagName('body')->item(0)) { foreach ($this->js as $js) { $script = $this->DOM->createElement('script'); $script->setAttribute('type', 'text/javascript'); $script->setAttribute('src', $js); $header->appendChild($script); } } } //set all the attributes foreach ($this->attributes as $id => $attribute) { if ($this->DOM->getElementById($id)) { $this->DOM->getElementById($id)->setAttribute($attribute[0], $attribute[1]); } } $pattern = array("/<\\/?{$this->delimiter}.*?>/"); if ($this->compact == false) { $pattern[] = "/<!--\\[.*?\\]-->|<!--.*?-->|\\s{2,}|\r|\t|\n/"; } $return = preg_replace($pattern, '', $this->DOM->saveHTML()); if (preg_match_all("/(<(area|base|basefont|br|col|frame|hr|img|input|link|meta|param).*?>)/", $return, $matches) > 0) { foreach ($matches[0] as $match) { $replace[] = substr($match, 0, -1) . '/>'; } } $return = str_replace($matches[0], $replace, $return); } else { if (isset($this->data['content'])) { $return = $this->data['content']; } } echo $return; }
/** * Build an individual gate file * * @param object &$gate reference to gate object * * @return string content of gate to write */ private function _parseGate(&$gate) { //init array for required file $required = array(); $code = ''; //foreach action $this->_parseGateCallback($gate, $code, $required); //get prepend tags $res = $this->sitemapDocument->getElementsByTagName('prepend'); $prependCode = ''; if ($res->length) { $prependGate = $res->item(0); $this->_parseGateCallback($prependGate, $prependCode, $required); } //add header and required files $content = $this->_addGateHeader($gate, $required); //add prepend and main code $content .= $prependCode . $code; $content .= $this->_addGateFooter($gate); return $content; }
/** * Constructor for a response message * * @param object $node A DOM document node. * * @return void */ public function __construct($node = null) { if (isset($node)) { $properties = get_object_vars($this); foreach ($properties as $var => $val) { $element = $node->getElementsByTagName($var); if ($element->length) { $this->{$var} = $element->item(0)->nodeValue; } } } }
/** * Returns up to MAX_LINK_PER_PAGE many links from the supplied * dom object where links have been canonicalized according to * the supplied $site information. * * @param object $dom a document object with links on it * @param string $sit a string containing a url * * @return array links from the $dom object */ static function links($dom, $site) { $sites = array(); $hyperlink = "http://schemas.openxmlformats.org/officeDocument/2006/" . "relationships/hyperlink"; $i = 0; $relationships = $dom->getElementsByTagName("Relationships"); foreach ($relationships as $relationship) { $relations = $relationship->getElementsByTagName("Relationship"); foreach ($relations as $relation) { if (strcmp($relation->getAttribute('Type'), $hyperlink) == 0) { if ($i < MAX_LINKS_TO_EXTRACT) { $link = $relation->getAttribute('Target'); $url = UrlParser::canonicalLink($link, $site); if (!UrlParser::checkRecursiveUrl($url) && strlen($url) < MAX_URL_LEN) { if (isset($sites[$url])) { $sites[$url] .= " " . $link; } else { $sites[$url] = $link; } $i++; } } } } } return $sites; }
/** * Determines the language of the html document by looking at the root * language attribute. If that fails $sample_text is used to try to guess * the language * * @param object $dom a document object to check the language of * @param string $sample_text sample text to try guess the language from * @param string $url url of web-page as a fallback look at the country * to figure out language * * @return string language tag for guessed language */ static function lang($dom, $sample_text = NULL, $url = NULL) { $htmls = $dom->getElementsByTagName("html"); $lang = NULL; foreach ($htmls as $html) { $lang = $html->getAttribute('lang'); if ($lang != NULL) { return $lang; } } if ($lang == NULL) { //baidu doesn't have a lang attribute but does say encoding $xpath = new DOMXPath($dom); $charset_check = "contains(translate(@http-equiv," . "'abcdefghijklmnopqrstuvwxyz'," . " 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),'CONTENT-TYPE')"; $metas = $xpath->evaluate("/html/head//meta[{$charset_check}]"); $found_metas = array(); foreach ($metas as $meta) { $content = $meta->getAttribute('content'); $charset_metas = explode("=", $content); if (isset($charset_metas[1])) { $charset = strtoupper($charset_metas[1]); $lang = guessLangEncoding($charset); return $lang; } } $lang = self::calculateLang($sample_text, $url); } return $lang; }
/** * process the Balsamiq XML file as a Fabrik form * @param object $xmlDoc DOMIT object */ protected function saveForm($xmlDoc, $view = 'form') { $post =& JRequest::get('post'); $params =& $post['params']; $controls =& $xmlDoc->getElementsByTagName('control'); $clength = $controls->getLength(); $fieldsets = $xmlDoc->getElementsByAttribute('controlTypeID', 'com.balsamiq.mockups::FieldSet'); $buttons = $xmlDoc->selectNodes("//*[@controlTypeID='com.balsamiq.mockups::Button']"); $blength = $buttons->getLength(); $fbuttons = array(); $allowedButtons = array('fabrik_save' => 'Submit', 'fabrik_copy' => 'Copy', 'fabrik_go_back' => 'Goback', 'fabrik_reset' => 'Reset', 'fabrik_apply' => 'apply', 'fabrik_delete' => 'delete'); for ($i = 0; $i < $blength; $i++) { $button = $buttons->item($i); $name = strip_tags((string) $button->getElementsByPath('controlProperties/customID')->toString()); $label = urldecode(strip_tags((string) $button->getElementsByPath('controlProperties/text')->toString())); if (in_array($name, array_keys($allowedButtons))) { switch ($name) { case 'fabrik_reset': $params['reset_button'] = 1; $params['reset_button_label'] = $label; break; case 'fabrik_go_back': $params['goback_button'] = 1; $params['goback_button_label'] = $label; break; case 'fabrik_copy': $params['copy_button'] = 1; $params['copy_button_label'] = $label; break; case 'fabrik_apply': $params['apply_button'] = 1; $params['apply_button_label'] = $label; break; case 'fabrik_save': JRequest::setVar('submit_button_label', $label); break; case 'fabrik_delete': $params['delete_button'] = 1; $params['delete_button_label'] = $label; //allow all to delete if this button is in the form $params['allow_delete'] = 0; break; } $fbuttons[] = array('text' => $label, 'name' => $name, 'x' => $button->getAttribute('x'), 'y' => $button->getAttribute('y'), 'h' => $button->getAttribute('h'), 'w' => $button->getAttribute('w')); } } $_POST['params'] = $params; $flength = $fieldsets->getLength(); for ($i = 0; $i < $flength; $i++) { $fieldset = $fieldsets->item($i); $label = strip_tags((string) $fieldset->getElementsByPath('controlProperties/text')->toString()); $name = strip_tags((string) $fieldset->getElementsByPath('controlProperties/customID')->toString()); if ($name == '') { $name = $label; } $fieldSetStyle = $this->parseControlProperties($fieldset); $this->groups[] = array('label' => $label, 'name' => $name, 'x' => $fieldset->getAttribute('x'), 'y' => $fieldset->getAttribute('y'), 'h' => $fieldset->getAttribute('h'), 'w' => $fieldset->getAttribute('w'), 'style' => $fieldSetStyle); } $html = array(); list($elements, $minX, $minY, $maxH) = $this->parseElements($xmlDoc, 'form'); foreach ($elements as &$element) { if (!array_key_exists('coords', $element)) { continue; //testing not sure this is right } $coords = $element['coords']; $ex = $coords['x']; $ey = $coords['y']; $ew = $coords['w']; $eh = $coords['h']; foreach ($this->groups as $gid => $g) { if ($ex >= $g['x'] && $ex + $ew <= $g['x'] + $g['w'] && $ey >= $g['y'] && $ey + $eh <= $g['y'] + $g['h']) { $element['groupid'] = $gid; //position element relative to group/fieldset $element['coords']['x'] = $ex - $g['x']; $element['coords']['y'] = $ey - $g['y']; //and the label coords if (array_key_exists('labelcoords', $element)) { $element['labelcoords']['x'] = $element['labelcoords']['x'] - $g['x']; $element['labelcoords']['y'] = $element['labelcoords']['y'] - $g['y']; } continue; } } } //ensure pk field is in first group $elements[$this->tbl . '___id']['groupid'] = array_shift(array_keys($this->groups)); $styles = array(); $formNode = $this->getFormNode($xmlDoc); if ($formNode == false) { $relativeXOffest = 0; $relativeYOffset = 0; $formStyle = ''; $formDims = array('w' => 0, 'h' => 0); } else { $formStyle = $this->parseControlProperties($formNode); $coords = $this->getCoords($formNode); $relativeXOffest = $coords['x']; $relativeYOffset = $coords['y']; $formDims = array('w' => $coords['w'], 'h' => $coords['h']); } foreach ($this->groups as $group) { $gkey = "fabrikGroup" . preg_replace("/[^A-Za-z0-9]/", "", $group['name']); /*$y = $group['y']; $x = $group['x'];*/ $w = $group['w']; $h = $group['h']; $x = $group['x'] - $relativeXOffest; $y = $group['y'] - $relativeYOffset; if ($formNode == false) { $formDims['h'] += $h; if ($w > $formDims['w']) { $formDims['w'] = $w; } } $styles[] = ".{$gkey}{ top:{$y}px;left:{$x}px;width:{$w}px;height:{$h}px;" . $group['style'] . " }"; } $styles[] = ".fabrikForm{ width:{$formDims['w']}px;height:{$formDims['h']}px;{$formStyle} }"; foreach ($elements as $key => &$element) { if (!array_key_exists('coords', $element)) { continue; //testing not sure this is right } if (array_key_exists('labelcoords', $element)) { $ly = $element['labelcoords']['y']; $lx = $element['labelcoords']['x']; $lw = $element['labelcoords']['w']; $lh = $element['labelcoords']['h']; $labelStyle = JArrayHelper::getValue($element, 'labelstyle'); $styles[] = "#fb_el_{$key}_text{ top:{$ly}px;left:{$lx}px;width:{$lw}px;height:{$lh}px;{$labelStyle} }"; $styles[] = "#fb_el_{$key}_ro_text{ top:{$ly}px;left:{$lx}px;width:{$lw}px;height:{$lh}px;{$labelStyle} }"; } $y = $element['coords']['y']; $x = $element['coords']['x']; $w = $element['coords']['w']; $h = $element['coords']['h']; $styles[] = ".{$key}{ top:{$y}px;left:{$x}px;width:{$w}px;height:{$h}px; }"; $styles[] = ".{$key}_ro{ top:{$y}px;left:{$x}px;width:{$w}px;height:{$h}px; }"; } //fabrik buttons foreach ($fbuttons as $fbutton) { $y = $fbutton['y']; $x = $fbutton['x']; $w = $fbutton['w']; $h = $fbutton['h']; $styles[] = "input[name=" . $allowedButtons[$fbutton['name']] . "]{ position:absolute;top:{$y}px;left:{$x}px;width:{$w}px;height:{$h}px; }"; } //copy and write out tmpl $tmplName = $params['tmpl_name']; $tmpLoc = JPATH_SITE . DS . 'tmp' . DS . $tmplName; if ($tmpLoc == '') { JError::raiseNotice(500, 'please supply a template name'); return; } if (!JFile::exists(JPATH_COMPONENT . DS . 'skeletons' . DS . 'form' . DS . 'default' . DS . 'template.css')) { JError::raiseError(500, 'Form skeleton css file not found: ' . JPATH_COMPONENT . DS . 'skeletons' . DS . 'form' . DS . 'default' . DS . 'template.css'); } $cssTmpl = JFile::read(JPATH_COMPONENT . DS . 'skeletons' . DS . 'form' . DS . 'default' . DS . 'template.css'); $cssTmpl = str_replace('{css}', implode("\n", $styles), $cssTmpl); if (JFolder::exists($tmpLoc)) { JFolder::delete($tmpLoc); } JFolder::copy(JPATH_COMPONENT . DS . 'skeletons' . DS . 'form' . DS . 'default', $tmpLoc); JFile::write($tmpLoc . DS . 'template.css', $cssTmpl); if ($view == 'details') { $tmplName .= '_details'; } $to = JPATH_SITE . DS . 'components' . DS . 'com_fabrik' . DS . 'views' . DS . 'form' . DS . 'tmpl' . DS . $tmplName; if (JFolder::exists($to)) { JFolder::delete($to); } JFolder::move($tmpLoc, $to); return $elements; }
/** * montaChaveXML * Monta a chave da NFe de 44 digitos com base em seus dados * Isso é útil no caso da chave formada no txt estar errada * * @name montaChaveXML * @param object $dom */ private function montaChaveXML($dom) { $ide = $dom->getElementsByTagName("ide")->item(0); $emit = $dom->getElementsByTagName("emit")->item(0); $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue; $dEmi = $ide->getElementsByTagName('dEmi')->item(0)->nodeValue; $CNPJ = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue; $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue; $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue; $nNF = $ide->getElementsByTagName('nNF')->item(0)->nodeValue; $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue; $cNF = $ide->getElementsByTagName('cNF')->item(0)->nodeValue; if (strlen($cNF) != 8) { $cNF = $ide->getElementsByTagName('cNF')->item(0)->nodeValue = rand(10000001, 99999999); } $tempData = $dt = explode("-", $dEmi); $forma = "%02d%02d%02d%s%02d%03d%09d%01d%08d"; $tempChave = sprintf($forma, $cUF, $tempData[0] - 2000, $tempData[1], $CNPJ, $mod, $serie, $nNF, $tpEmis, $cNF); $cDV = $ide->getElementsByTagName('cDV')->item(0)->nodeValue = $this->calculaDV($tempChave); $this->chave = $tempChave .= $cDV; $infNFe = $dom->getElementsByTagName("infNFe")->item(0); $infNFe->setAttribute("Id", "NFe" . $this->chave); }
/** * Returns the value of the requested XML tag name, which must be unique. * * @param object $dom an XML DOM document instance * @param string $tag the name of the tag * @param string $namespace an optional namespace for the tag * @return mixed the tag's value * * @since 0.4 */ public function get_single_xml_tag_value($dom, $tag, $namespace = "") { if ($namespace) { $tags = $dom->getElementsByTagNameNS($namespace, $tag); } else { $tags = $dom->getElementsByTagName($tag); } return $tags->item(0)->nodeValue; }
/** * zTestaChaveXML * Remonta a chave da NFe de 44 digitos com base em seus dados * Isso é útil no caso da chave informada estar errada * se a chave estiver errada a mesma é substituida * @param object $dom */ private function zTestaChaveXML($dom) { $infNFe = $dom->getElementsByTagName("infNFe")->item(0); $ide = $dom->getElementsByTagName("ide")->item(0); $emit = $dom->getElementsByTagName("emit")->item(0); $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue; $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue; $cnpj = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue; $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue; $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue; $nNF = $ide->getElementsByTagName('nNF')->item(0)->nodeValue; $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue; $cNF = $ide->getElementsByTagName('cNF')->item(0)->nodeValue; $chave = str_replace('NFe', '', $infNFe->getAttribute("Id")); $tempData = explode("-", $dhEmi); $chaveMontada = $this->montaChave($cUF, $tempData[0] - 2000, $tempData[1], $cnpj, $mod, $serie, $nNF, $tpEmis, $cNF); //caso a chave contida na NFe esteja errada //substituir a chave if ($chaveMontada != $chave) { $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1); $infNFe = $dom->getElementsByTagName("infNFe")->item(0); $infNFe->setAttribute("Id", "NFe" . $chaveMontada); $this->chNFe = $chaveMontada; } }
/** * Embed external files in EPUB * * @param object $doc * @param object $epub */ function toolbook_exportepub_embed_external_files($doc, $epub) { foreach ($doc->getElementsByTagName('img') as $element) { if (!$element->hasAttribute('src')) { continue; } $url = $element->getAttribute('src'); list($data, $name, $type) = toolbook_exportepub_http_get($url); if ($data) { $item = $epub->add_item($data, $type, 'images/' . $name); $element->setAttribute('src', $item['href']); } } foreach ($doc->getElementsByTagName('video') as $element) { if (!$element->hasAttribute('src')) { continue; } $url = $element->getAttribute('src'); list($data, $name, $type) = toolbook_exportepub_http_get($url); if ($data) { $item = $epub->add_item($data, $type, 'images/' . $name); $element->setAttribute('src', $item['href']); } } foreach ($doc->getElementsByTagName('audio') as $element) { if (!$element->hasAttribute('src')) { continue; } $url = $element->getAttribute('src'); list($data, $name, $type) = toolbook_exportepub_http_get($url); if ($data) { $item = $epub->add_item($data, $type, 'images/' . $name); $element->setAttribute('src', $item['href']); } } foreach ($doc->getElementsByTagName('source') as $element) { if (!$element->hasAttribute('src')) { continue; } $url = $element->getAttribute('src'); list($data, $name, $type) = toolbook_exportepub_http_get($url); if (!$type and $element->hasAttribute('type')) { $type = $element->getAttribute('type'); } if ($data) { $item = $epub->add_item($data, $type, 'images/' . $name); $element->setAttribute('src', $item['href']); } } foreach ($doc->getElementsByTagName('object') as $element) { if (!$element->hasAttribute('data')) { continue; } $url = $element->getAttribute('data'); list($data, $name, $type) = toolbook_exportepub_http_get($url); if (!$type and $element->hasAttribute('type')) { $type = $element->getAttribute('type'); } if ($data) { $item = $epub->add_item($data, $type, 'images/' . $name); $element->setAttribute('data', $item['href']); } } }