/** * @param unknown $text * @return Ambigous <string, mixed> */ private function get_text($text) { // Strip links first $text = preg_replace("/<\\/?a(\\s+.*?>|>)/", "", $text); $html2Text = new \Html2Text\Html2Text($text); $text = $html2Text->get_text(); // Strip multiply spaces and remove line breaks $text = preg_replace('/\\s+/m', ' ', $text); $text = \Rss\Util\Helpers\Helpers::fix_smartquotes($text); return $text; }
/** * * @param Zend\Feed\Reader\Feed\Rss $feed * @return string */ private function fix_links($feed, $uri) { // Fix relative links $feedhost = $feed->getLink(); $feedhost = parse_url($feedhost, PHP_URL_HOST); if (!$feedhost) { $feedhost = parse_url($uri, PHP_URL_HOST); $feedhost = explode(".", $feedhost); $feedhost[0] = "www"; $feedhost = implode(".", $feedhost); } $feeddata = $feed->saveXml(); $doc = new \DOMDocument('1.0', 'UTF-8'); @$doc->loadXML($feeddata); $xpath = new \DOMXpath($doc); foreach ($xpath->query('//link') as $node) { $link = $node->nodeValue; $link = \Rss\Util\Helpers\Helpers::unquote(trim($link), '""\'\''); $link = rawurldecode($link); $link = html_entity_decode($link, ENT_QUOTES, "UTF-8"); $link = htmlspecialchars_decode($link, ENT_QUOTES); $link = filter_var($link, FILTER_SANITIZE_URL); $linkhost = parse_url($link, PHP_URL_HOST); $node->nodeValue = htmlentities($link); if ($linkhost) { continue; } $link = "http://" . $feedhost . $link; $node->nodeValue = htmlentities($link); } return $doc->saveXML(); }
/** * Get the text from an html string * * @param string $text * @return string * */ private function get_text($text) { if (!is_array($text)) { $this->logger->logWarn("Invalid text ", array(json_decode($text))); return null; } for ($i = 0; $i < count($text); $i++) { // Strip multiply spaces and remove line breaks $text[$i] = preg_replace('/\\s+/m', ' ', $text[$i]); $text[$i] = trim($text[$i]); } $text = implode(" ", $text); $text = htmlspecialchars_decode($text, ENT_QUOTES); $text = \Rss\Util\Helpers\Helpers::fix_smartquotes($text); return $text; }
/** * Get the text from an html string * * @param string $text * @return string * */ private function get_text($text) { // Strip links first because Html2Text puts them in the output $text = preg_replace("/<\\/?a(\\s+.*?>|>)/", "", $text); $html2Text = new \Html2Text\Html2Text($text); $text = $html2Text->get_text(); $text = html_entity_decode($text, ENT_QUOTES); // Strip multiply spaces and remove line breaks $text = preg_replace('/\\s+/m', ' ', $text); $text = \Rss\Util\Helpers\Helpers::fix_smartquotes($text); $text = trim($text); return $text; }