/** * montaMessagem * * @param string $pathFile */ protected function montaMessagem($pathFile) { $dom = new Dom(); $dom->loadXMLFile($pathFile); $infMDFe = $dom->getNode('infMDFe', 0); $ide = $infMDFe->getElementsByTagName('ide')->item(0); $emit = $infMDFe->getElementsByTagName('emit')->item(0); $tot = $infMDFe->getElementsByTagName('tot')->item(0); $razao = $emit->getElementsByTagName('xNome')->item(0)->nodeValue; $nMDF = $ide->getElementsByTagName('nMDF')->item(0)->nodeValue; $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue; $dhEmi = !empty($ide->getElementsByTagName('dhEmi')->item(0)->nodeValue) ? $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue : $ide->getElementsByTagName('dEmi')->item(0)->nodeValue; $data = date('d/m/Y', DateTime::convertSefazTimeToTimestamp($dhEmi)); $vCarga = $tot->getElementsByTagName('vCarga')->item(0)->nodeValue; $xNome = ''; $this->msgHtml = $this->renderTemplate($xNome, $data, $nMDF, $serie, $vCarga, $razao); $cHTT = new Html2Text($this->msgHtml); $this->msgTxt = $cHTT->getText(); return "MDFe n. {$nMDF} - {$razao}"; }
/** * zMontaMessagem * * @param string $pathFile */ protected function zMontaMessagem($pathFile) { $dom = new Dom(); $dom->loadXMLFile($pathFile); $infCTe = $dom->getNode('infCte', 0); $ide = $infCTe->getElementsByTagName('ide')->item(0); $dest = $infCTe->getElementsByTagName('dest')->item(0); $emit = $infCTe->getElementsByTagName('emit')->item(0); $vPrest = $infCTe->getElementsByTagName('vPrest')->item(0); $razao = $emit->getElementsByTagName('xNome')->item(0)->nodeValue; $nCT = $ide->getElementsByTagName('nCT')->item(0)->nodeValue; $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue; $xNome = $dest->getElementsByTagName('xNome')->item(0)->nodeValue; $dhEmi = !empty($ide->getElementsByTagName('dhEmi')->item(0)->nodeValue) ? $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue : $ide->getElementsByTagName('dEmi')->item(0)->nodeValue; $data = date('d/m/Y', DateTime::convertSefazTimeToTimestamp($dhEmi)); $vCT = $vPrest->getElementsByTagName('vTPrest')->item(0)->nodeValue; $this->aMail[] = !empty($dest->getElementsByTagName('email')->item(0)->nodeValue) ? $dest->getElementsByTagName('email')->item(0)->nodeValue : ''; $this->msgHtml = $this->zRenderTemplate($xNome, $data, $nCT, $serie, $vCT, $razao); $cHTT = new Html2Text($this->msgHtml); $this->msgTxt = $cHTT->getText(); return "CTe n. {$nCT} - {$razao}"; }
public function getMessageAsPlainText(array $config = []) { if (empty($config)) { $config = ['do_links' => 'none']; } $html = new Html2Text($this->message, $config); return $html->getText(); }
/** * zMontaMessagem * * @param string $pathFile */ protected function zMontaMessagem($pathFile) { $dom = new Dom(); $dom->loadXMLFile($pathFile); $infNFe = $dom->getNode('infNFe', 0); $ide = $infNFe->getElementsByTagName('ide')->item(0); $dest = $infNFe->getElementsByTagName('dest')->item(0); $emit = $infNFe->getElementsByTagName('emit')->item(0); $icmsTot = $infNFe->getElementsByTagName('ICMSTot')->item(0); $razao = $emit->getElementsByTagName('xNome')->item(0)->nodeValue; $nNF = $ide->getElementsByTagName('nNF')->item(0)->nodeValue; $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue; $xNome = $dest->getElementsByTagName('xNome')->item(0)->nodeValue; $dhEmi = !empty($ide->getElementsByTagName('dhEmi')->item(0)->nodeValue) ? $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue : $ide->getElementsByTagName('dEmi')->item(0)->nodeValue; $data = date('d/m/Y', DateTime::convertSefazTimeToTimestamp($dhEmi)); $vNF = $icmsTot->getElementsByTagName('vNF')->item(0)->nodeValue; $this->aMail[] = !empty($dest->getElementsByTagName('email')->item(0)->nodeValue) ? $dest->getElementsByTagName('email')->item(0)->nodeValue : ''; //pega os emails que existirem em obsCont $infAdic = $infNFe->getElementsByTagName('infAdic')->item(0); if (!empty($infAdic)) { $obsConts = $infAdic->getElementsByTagName('obsCont'); foreach ($obsConts as $obsCont) { if (strtoupper($obsCont->getAttribute('xCampo')) === 'EMAIL') { $this->aMail[] = $obsCont->getElementsByTagName('xTexto')->item(0)->nodeValue; } } } $this->msgHtml = $this->zRenderTemplate($xNome, $data, $nNF, $serie, $vNF, $razao); $cHTT = new Html2Text($this->msgHtml); $this->msgTxt = $cHTT->getText(); return "NFe n. {$nNF} - {$razao}"; }
/** * Convert html to text * @param string $html * @return string */ private function htmlToText($html) { $converter = new Html2Text($html); return $converter->getText(); }
/** * @param $tpl * @param array $variables * @return array */ protected function _getTemplateData($tpl, array $variables = []) { $tplData = explode('######', $this->_renderMail($tpl, $variables)); $tplData = array_map('trim', $tplData); foreach ($tplData as $row) { $parts = array_map('trim', explode(':', $row, 2)); switch (strtolower($parts[0])) { case 'subject': $subject = $parts[1]; break; case 'html': $html = $parts[1]; break; case 'plain': $plain = $parts[1]; break; default: } } if (!isset($subject)) { $subject = 'Missing subject'; } if (!isset($html)) { $html = 'Missing html content'; } if (!isset($plain)) { $htmlConverter = new Html2Text($html); $plain = $htmlConverter->getText(); } return array($subject, $html, $plain); }
/** * {@inheritdoc} */ public function createService(SimpleXMLElement $service) { // read the service name $serviceName = (string) $service['name']; $serviceClassName = $serviceName; $serviceClassName = filter_var($serviceClassName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeVariableName'))); $serviceClassName = filter_var($serviceClassName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeConstantName'))); /* * CLASS CREATION */ // create the class $class = ClassGenerator::fromReflection(new ClassReflection('\\Sapone\\Template\\ServiceTemplate')); $class->setName($serviceClassName); $class->setNamespaceName($this->namespaceInflector->inflectNamespace($service)); // set the correct inheritance if ($this->config->isBesimpleClient()) { $class->setExtendedClass('BeSimpleSoapClient'); $class->addUse('BeSimple\\SoapClient\\SoapClient'); } else { $class->setExtendedClass('\\SoapClient'); } // read the service documentation $serviceDoc = new DocBlockGenerator(); $serviceDoc->setTag(new GenericTag('xmlns', '@todo')); $documentation = new Html2Text((string) current($service->xpath('./wsdl:documentation'))); if ($documentation->getText()) { $serviceDoc->setShortDescription($documentation->getText()); } $class->setDocBlock($serviceDoc); /* * METHODS CREATION */ foreach ($service->xpath('.//wsdl:operation') as $operation) { $operationName = (string) $operation['name']; $operationName = filter_var($operationName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeVariableName'))); $operationName = filter_var($operationName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeConstantName'))); $inputMessageType = $this->getTypeFromQualifiedString((string) current($operation->xpath('.//wsdl:input/@message')), $operation); $outputMessageType = $this->getTypeFromQualifiedString((string) current($operation->xpath('.//wsdl:output/@message')), $operation); // read the service documentation $messageDoc = new DocBlockGenerator(); $documentation = new Html2Text((string) current($operation->xpath('./wsdl:documentation'))); $param = new ParameterGenerator('parameters', $inputMessageType); $messageDoc->setTag(new ParamTag($param->getName(), $this->namespaceInflector->inflectDocBlockQualifiedName($inputMessageType))); $messageDoc->setTag(new ReturnTag($this->namespaceInflector->inflectDocBlockQualifiedName($outputMessageType))); if ($documentation->getText()) { $messageDoc->setShortDescription($documentation->getText()); } // create the method $method = new MethodGenerator($operationName); $method->setDocBlock($messageDoc); $method->setParameter($param); $method->setBody("return \$this->__soapCall('{$operation['name']}', array(\$parameters));"); $class->addMethodFromGenerator($method); } $this->serializeClass($class); // register the class in the classmap $this->classmap[$class->getName()] = $class->getNamespaceName() . '\\' . $class->getName(); return $class->getName(); }