function fetch_data_from_html($remote_page) { // Returns an array of products and ratings $product_rating_arr = array(); $html = get_html($remote_page); $dom = new domDocument(); $dom->loadHTML($html); $dom->preserveWhiteSpace = false; $tables = $dom->getElementsByTagName('table'); $table = $tables->item(0); $rows = $table->getElementsByTagName('tr'); $i = 0; foreach ($rows as $row) { if ($i != 0) { $columns = $row->getElementsByTagName('td'); $product = $columns->item(0)->textContent; $rating = $columns->item(1)->textContent; $image = $columns->item(2)->textContent; $var = $product . "__" . $image; $product_rating_arr[$var] = $rating; } $i += 1; } return $product_rating_arr; }
public function getContent($params = array()) { $awsCachePath = CACHEPATH . "/aws.status.cxml"; $data = array(); $neededLocations = array(); $services = array('Amazon Elastic Compute Cloud', 'Amazon Relational Database Service', 'Amazon Simple Storage Service'); $compliance = array('us-east-1' => array('name' => 'NA_block', 'filter' => array('N. Virginia', 'US Standard')), 'us-west-1' => array('name' => 'NA_block', 'filter' => 'N. California'), 'us-west-2' => array('name' => 'NA_block', 'filter' => 'Oregon'), 'sa-east-1' => array('name' => 'SA_block', 'filter' => ''), 'eu-west-1' => array('name' => 'EU_block', 'filter' => ''), 'ap-southeast-1' => array('name' => 'AP_block', 'filter' => 'Singapore'), 'ap-southeast-2' => array('name' => 'AP_block', 'filter' => 'Sydney'), 'ap-northeast-1' => array('name' => 'AP_block', 'filter' => 'Tokyo')); if (empty($params['locations'])) { $neededLocations = $this->getUsedLocations(); $params['locations'] = $neededLocations; } else { $neededLocations = $params['locations']; } if (file_exists($awsCachePath) && time() - filemtime($awsCachePath) < 3600) { clearstatcache(); $time = filemtime($awsCachePath); $data = (array) json_decode(file_get_contents($awsCachePath)); } else { $html = @file_get_contents('http://status.aws.amazon.com'); if ($html) { $dom = new domDocument(); $dom->validateOnParse = false; @$dom->loadHTML($html); $dom->preserveWhiteSpace = false; foreach ($compliance as $compKey => $compValue) { $div = $dom->getElementById($compValue['name']); $tables = $div->getElementsByTagName('table'); $rows = $tables->item(0)->getElementsByTagName('tr'); foreach ($rows as $row) { $cols = $row->getElementsByTagName('td'); if (preg_match('/(.*)(' . implode('|', $services) . ')(.*)/', $cols->item(1)->nodeValue)) { $regionFilter = $compValue['filter']; if (is_array($compValue['filter'])) { $regionFilter = implode('|', $compValue['filter']); } if (preg_match('/(.*)(' . $regionFilter . ')(.*)/', $cols->item(1)->nodeValue)) { $img = ''; $message = ''; if ($cols->item(0)->getElementsByTagName('img')->item(0)->getAttribute('src') == 'images/status0.gif') { $img = 'normal.png'; } else { $img = 'disruption.png'; $message = $cols->item(2)->nodeValue; } $data[$compKey][substr(str_replace($services, array('EC2', 'RDS', 'S3'), $cols->item(1)->nodeValue), 0, strpos(str_replace($services, array('EC2', 'RDS', 'S3'), $cols->item(1)->nodeValue), ' ('))] = array('img' => $img, 'status' => $cols->item(2)->nodeValue, 'message' => $message); $data[$compKey]['locations'] = $compKey; } } } } file_put_contents($awsCachePath, json_encode($data)); } } $retval = array('locations' => json_encode($neededLocations)); foreach ($neededLocations as $value) { $retval['data'][] = $data[$value]; } return $retval; }
public function findWspolrzedne($adres, $miasto) { $adresTrim = trim($adres); $adresReplaceSpace = str_replace(' ', '+', $adresTrim); $LettersToChange = array('ó', 'ż', 'ź', 'ś', 'ę', 'ą', 'ł', 'ń', 'ć'); $LettersChanged = array('o', 'z', 'z', 's', 'e', 'a', 'l', 'n', 'c'); $adresWithoutPolishLetters = str_replace($LettersToChange, $LettersChanged, $adresReplaceSpace); $curl1 = curl_init(); curl_setopt($curl1, CURLOPT_URL, "http://www.zumi.pl/namapie.html?qt=&loc={$miasto}%2C+{$adresWithoutPolishLetters}&Submit=Szukaj&cId=&sId="); curl_setopt($curl1, CURLOPT_RETURNTRANSFER, 1); $stronaZumi = curl_exec($curl1); curl_close($curl1); $dom = new domDocument(); @$dom->loadHTML($stronaZumi); $dom->preserveWhiteSpace = false; $szukana = array(); $divs = $dom->getElementsByTagName('div'); foreach ($divs as $div) { $script = $div->getElementsByTagName('script'); $szukana[] = $script->item(0)->nodeValue; } foreach ($szukana as $text) { if (strpos($text, 'objDefLoc')) { $a = substr($text, -29); $letterToRemove = array(':', '"', 'y', 'x', '}'); $wspolrzedne1 = str_replace($letterToRemove, '', $a); $poz = strpos($wspolrzedne1, ','); $dlugosc = substr($wspolrzedne1, $poz); $dlugosc = str_replace(',', '', $dlugosc); $szerokosc = substr($wspolrzedne1, 0, $poz); $wspolrzedne[] = "{$dlugosc},{$szerokosc}"; } } return $wspolrzedne[0]; }
public function __construct($html, $baseurl) { $doc = new domDocument(); $doc->loadHTML($html); $this->body = $doc->getElementsByTagName('html')->item(0)->getElementsByTagName('body')->item(0); $this->lines = array(); $this->line = (object) array('text' => '', 'wrap' => true, 'prefix' => "\n"); $this->pre = 0; $this->indent = array(); $this->baseurl = $baseurl; $this->links = array(); $this->linkcount = 0; }
function get_pre($url) { $html = file_get_contents($url); // a new dom object $dom = new domDocument('1.0', 'utf-8'); // load the html into the object ***/ @$dom->loadHTML($html); //discard white space $dom->preserveWhiteSpace = false; $pre = $dom->getElementsByTagName('pre'); //Get elements by desired tag. return htmlspecialchars($pre->item(0)->nodeValue); }
function prepareContent($content) { if (!$content) { return ''; } $dom = new domDocument(); $dom->loadHTML('<?xml encoding="UTF-8">' . $content); $images = $dom->getElementsByTagName('img'); foreach ($images as $image) { $src = $image->getAttribute('src'); $image->setAttribute('src', site_url($src)); } return $dom->saveHTML(); }
function get_instituicao_cursos($cod_endereco, $cod_instituicao) { $html = file_get_contents('http://emec.mec.gov.br/emec/consulta-ies/listar-curso-endereco/d96957f455f6405d14c6542552b0f6eb/' . base64_encode($cod_instituicao) . '/aa547dc9e0377b562e2354d29f06085f/' . base64_encode($cod_endereco) . '/list/1000'); include_once './src/simple_html_dom.php'; $dom = new domDocument(); @$dom->loadHTML($html); $dom->preserveWhiteSpace = false; $tables = $dom->getElementsByTagName('tbody'); foreach ($tables as $row) { $cols = $row->getElementsByTagName('td'); $array[] = preg_replace("/[^A-Za-z]/", "", $cols->item(0)->nodeValue); } return $array; }
public function toRichTextObject($html) { $this->initialise(); // Create a new DOM object $dom = new domDocument(); // Load the HTML file into the DOM object // Note the use of error suppression, because typically this will be an html fragment, so not fully valid markup $loaded = @$dom->loadHTML($html); // Discard excess white space $dom->preserveWhiteSpace = false; $this->richTextObject = new PHPExcel_RichText(); $this->parseElements($dom); return $this->richTextObject; }
/** * Extract selected items array from html multiselect tag * * @param array Html multiselect tag * @return array Selected items array */ private function getSelectedItems($html) { $dom = new domDocument(); $dom->loadHTML($html); $dom->preserveWhiteSpace = false; $options = $dom->getElementsByTagname('option'); $items = array(); foreach ($options as $option) { if ($option->hasAttribute('selected')) { $items[] = $option->nodeValue; } } return $items; }
/** * parseLicenseTbl * \brief given a fossology license histogram, parse it into license * names and Show links. * * @returns an array of associative arrays with keys of: * count, showLink, textOrLink. the values will be the license count * the url of the Show link and whatever is in the next column. This * can be text or a link or ? * * Sets property noRows. * * An empty array if no license histogram on that page, * */ function parseLicenseTbl() { /* * Each table row has 3 td's in it. First is the license count, second * is the show link and third is the license name. */ $dom = new domDocument(); @$dom->loadHTML($this->page); /*** discard white space ***/ $dom->preserveWhiteSpace = false; $table = $dom->getElementById($this->tableId); if (empty($table)) { $this->emptyTable = TRUE; //print "DPLTDB: table is empty, can't find table! with table id of:$this->tableId\n"; return $this->hList = array(); } foreach ($table->childNodes as $tblChildNode) { $histogram = array(); foreach ($tblChildNode->childNodes as $childNode) { if ($childNode->nodeName == 'td') { if (is_numeric($childNode->nodeValue)) { $histogram['count'] = trim($childNode->nodeValue); } if ($childNode->nodeValue == 'Show') { $anchorList = $childNode->getElementsByTagName('a'); foreach ($anchorList as $anchorEle) { $histogram['showLink'] = $anchorEle->getAttribute('href'); } } if (is_string($childNode->nodeValue)) { $histogram['textOrLink'] = trim($childNode->nodeValue); } } } // foreach($tblChildNode $this->hList[] = $histogram; $histogram = array(); } // foreach // for tables with titles, the first row is empty as no childNodes match // what we are looking for, remove the first row. if ($this->title) { // remove empty 1st entry unset($this->hList[0]); } if (empty($this->hList)) { $this->noRows = TRUE; } }
private function asSimpleXml($str) { if (stripos($str, '<!DOCTYPE html') !== false) { // we've got to parse the html first $dom = new domDocument(); // hack needed or else loadHTML won't work with utf-8: @$dom->loadHTML('<?xml encoding="UTF-8">' . $str); $simpleXmlObj = simplexml_import_dom($dom); } elseif (stripos($str, '<?xml') === 0) { $simpleXmlObj = simplexml_load_string($str); } else { throw new Exception("Can't parse as XML or HTML."); } return $simpleXmlObj; }
private function parseTags($tag = '', $source = "") { if (!$tag) { throw new Exception\CrawlException('Tag has type of null'); } /*** a new dom object ***/ $dom = new \domDocument(); @$dom->loadHTML($source); /*** remove silly white space ***/ $dom->preserveWhiteSpace = false; /*** get the links from the HTML ***/ // $tag->setTag('a'); $tags = $dom->getElementsByTagName($tag); return $tags; }
/** * * from http://www.phpro.org/examples/Get-Text-Between-Tags.html * * @get text between tags * @param string $tag The tag name * @param string $html The XML or XHTML string * @param int $strict Whether to use strict mode * @return array * */ function getTextBetweenTags($tag, $html, $strict = 0) { $dom = new domDocument(); if ($strict == 1) { $dom->loadXML($html); } else { $dom->loadHTML($html); } $dom->preserveWhiteSpace = false; $content = $dom->getElementsByTagname($tag); $out = array(); foreach ($content as $item) { $out[] = $item->nodeValue; } return $out; }
/** * This function returns an associative array containing information * about every WoW Server. * * The associative array is in the following format: * "name" - Name of the server. * "status" - Status of the server ("up" or "down") * "type" - Type of server (PvE, PvP, RP) * "population" - Low, Medium, High server status. * "locale" - Location of WoW Server (United States by default) */ function getAllServers() { if($this->SERVER_ARRAY == null) { $dom = new domDocument; $dom->loadHTML(file_get_contents($this->STATUS_URL)); $dom->preserveWhiteSpace = false; $xpath = new DOMXPath($dom); $name = $xpath->query('//td[@class="name"]'); $status = $xpath->query('//td[@class="status"]/div/@class'); $type = $xpath->query('//td[@class="type"]/span'); $population = $xpath->query('//td[@class="population"]/span'); $locale = $xpath->query('//td[@class="locale"]'); /* Generate the number of servers */ $ctr = 0; foreach($name as $n) { $ctr++; } $serverArray = array(); for($i=0;$i<$ctr;$i++) { $s = explode(" ", trim($status->item($i)->nodeValue)); $info = array ( "name" => trim(utf8_decode($name->item($i)->nodeValue)), "status" => $s[1], "type" => substr(substr(trim($type->item($i)->nodeValue),0,-1),1), "population" => trim($population->item($i)->nodeValue), "locale" => trim(utf8_decode($locale->item($i)->nodeValue)) ); array_push($serverArray, $info); } $this->SERVER_ARRAY = $serverArray; } return $this->SERVER_ARRAY; }
public function findMonitor($szukana) { $curl1 = curl_init(); curl_setopt($curl1, CURLOPT_URL, "http://www.samsung.com/pl/function/espsearch/searchResult.do?keywords={$szukana}&input_keyword={$szukana}"); curl_setopt($curl1, CURLOPT_RETURNTRANSFER, 1); $strona1 = curl_exec($curl1); curl_close($curl1); $dom1 = new domDocument(); @$dom1->loadHTML($strona1); $dom1->preserveWhiteSpace = false; $nazwa = array(); $a = $dom1->getElementsByTagName('a'); foreach ($a as $a) { $class = $a->getAttribute('class'); $href = $a->getAttribute('href'); $nazwa[$class] = $href; } $nazwa2 = $nazwa['arrow_blue']; $url = "{$nazwa2}&tab=specification"; $curl2 = curl_init(); curl_setopt($curl2, CURLOPT_URL, "{$url}"); curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1); $strona2 = curl_exec($curl2); curl_close($curl2); $tabela = array(); $dom2 = new domDocument(); @$dom2->loadHTML($strona2); $dom2->preserveWhiteSpace = false; $nazwa = $dom2->getElementsByTagName('h1'); $tabela['nazwa'] = $nazwa->item(0)->nodeValue; $rows = $dom2->getElementsByTagName('tr'); foreach ($rows as $row) { $th = $row->getElementsByTagName('th'); $nazwa = $th->item(0)->nodeValue; $nazwa2 = $th->item(1)->nodeValue; $td = $row->getElementsByTagName('td'); $wartosc = $td->item(0)->nodeValue; $tabela[trim($nazwa)] = trim($wartosc); $tabela[trim($nazwa2)] = trim($wartosc); } $correctTable = $this->removeAllWrongValueFromTable($tabela); return $correctTable; }
private function _grab($date) { $content = new domDocument(); // кривая разметка камы @$content->loadHTML(file_get_contents($this->_url . '?date=' . date('Y-m-d', $date))); $rows = $content->getElementsByTagName('tr'); $result = array(); for ($i = 2; $i < $rows->length; $i++) { $cols = $rows->item($i)->getElementsByTagName('td'); $item = array('title' => $cols->item(1)->nodeValue, 'description' => 'Зал: ' . $cols->item(4)->nodeValue, 'fire_at' => date('Y-m-d ', $date) . trim(substr($cols->item(0)->nodeValue, 2))); if ($cols->item(4)->nodeValue == 1) { $item['description'] .= sprintf("\n\nЭконом: %s р.\nVIP: %s р.", $cols->item(2)->nodeValue, $cols->item(3)->nodeValue); } else { $item['description'] .= sprintf("\n\nЦена: %s р.", $cols->item(3)->nodeValue); } $result[] = $item; } return $result; }
function parse_content() { $this->im = ""; if ($this->content == "") { return; } $dom = new domDocument(); @$dom->loadHTML($this->content); $dom->preserveWhiteSpace = false; @($images = $dom->getElementsByTagName('img')); if ($images->length > 0) { if ($images->length > $this->imagenum) { $this->im = $images->item($this->imagenum)->getAttribute('src'); } else { $this->imagenum = 0; $this->im = $images->item(0)->getAttribute('src'); } } }
public function getPrice($marka, $nazwa) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "http://www.ceneo.pl/Monitory;004+s{$marka}~~M{$nazwa}"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $strona = curl_exec($curl); curl_close($curl); $dom = new domDocument(); @$dom->loadHTML($strona); $dom->preserveWhiteSpace = false; $table = array(); $bigs = $dom->getElementsByTagName('big'); foreach ($bigs as $big) { $strong = $big->getElementsByTagName('strong'); $cena = $strong->item(0)->nodeValue; $table[] = $cena; } return $table[0]; }
protected function formatCode($article) { echo $cont = $article['content']; $dom = new \domDocument(); $dom->loadHTML($cont); $dom->preserveWhiteSpace = false; $codeelement = $dom->getElementsByTagname('code'); $i = $codeelement->length - 1; while ($i > -1) { $element = $codeelement->item($i); echo $element->nodeValue; echo "<br />"; echo $newelement = htmlentities($element->nodeValue); exit; $element->parentNode->replaceChild($newelement, $element); $i--; } exit; return $article; }
function getTextBetweenTags($tag, $html, $strict = 0) { /*** a new dom object ***/ //$dom = new domDocument; $dom = new domDocument('1.0', 'UTF-8'); /*** load the html into the object ***/ $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); @$dom->loadHTML($html); /*** discard white space ***/ $dom->preserveWhiteSpace = false; /*** the tag by its tag name ***/ $content = $dom->getElementsByTagname($tag); /*** the array to return ***/ ////$out = array(); $out = ""; foreach ($content as $item) { /*** add node value to the out array ***/ $out .= "\"" . $item->nodeValue . "\", "; } /*** return the results ***/ return $out; }
/** * * @get text between tags * * @param string $tag The tag name * * @param string $html The XML or XHTML string * * @param int $strict Whether to use strict mode * * @return array * */ function getTextBetweenTags($tag, $html, $strict = 0) { /*** a new dom object ***/ $dom = new domDocument(); /*** load the html into the object ***/ if ($strict == 1) { $dom->loadXML($html); } else { $dom->loadHTML($html); } /*** discard white space ***/ $dom->preserveWhiteSpace = false; /*** the tag by its tag name ***/ $content = $dom->getElementsByTagname($tag); /*** the array to return ***/ $out = array(); foreach ($content as $item) { /*** add node value to the out array ***/ $out[] = $item->nodeValue; } /*** return the results ***/ return $out; }
function iterateMensaMenu() { /*** a new dom object ***/ $dom = new domDocument(); /*** load the html into the object - @ catches the warnings from malformed html ***/ @$dom->loadHTML($webdata); /*** discard white space ***/ $dom->preserveWhiteSpace = false; /*** the table by its tag name ***/ $tables = $dom->getElementsByTagName('table'); foreach ($tables as $table) { $rows = $table->getElementsByTagName('tr'); foreach ($rows as $row) { foreach (array('th', 'td') as $col_identifier) { $cols = $row->getElementsByTagName($col_identifier); foreach ($cols as $col) { echo $col->nodeValue; } echo '<br />'; } } echo '<hr />'; } }
function getUnfilteredWebData($place_origin, $name_origin, $place_destination, $type_destination) { global $config_url_efa; $curl_conenction = prepare_curl_connection($config_url_efa); $post_data = build_post_array($place_origin, $name_origin, $place_destination, $type_destination); $result = execute_curl_connection($curl_conenction, $post_data); /*** a new dom object ***/ $dom = new domDocument(); @$dom->loadHTML($result); $dom->preserveWhiteSpace = false; $table_list = $dom->getElementsByTagName('table'); foreach ($table_list as $table) { if ($table->hasAttributes()) { foreach ($table->attributes as $attribute) { if ($attribute->value == "100%") { $dom_ele_timetable = $table; break; } } } } $xml_string = str_replace(" ", "", $dom->saveXML($dom_ele_timetable)); return $xml_string; }
public function mapPost($blog, $strip_tags = '', $text_length = 0, $skip = array()) { $creator = JFactory::getUser($blog->created_by); $item = new PostSimpleSchema(); $item->textplain = $blog->fulltext; $item->postid = $blog->id; $item->title = $blog->title; $item->introtext = $this->sanitize($blog->introtext); $item->text = $this->sanitize($blog->fulltext); if (empty($item->text)) { $item->text = $blog->introtext . " " . $blog->fulltext; $item->textplain = $blog->introtext . " " . $blog->fulltext; } $item->textplain = $item->textplain; $item->image = new stdClass(); $img_obj = json_decode($blog->images); if (isset($img_obj->image_intro)) { $item->image->intro_url = (string) JURI::root() . $img_obj->image_intro; $item->image->full_image_url = JURI::root() . $img_obj->image_fulltext; } else { $item->image->intro_url = null; $item->image->full_image_url = null; } $item->created_date = JHTML::_('date', $blog->created, JText::_('DATE_FORMAT_LC2')); $item->author->name = $creator->username; $item->author->photo = null; $item->category->categoryid = $blog->catid; $item->category->title = $blog->category_title; $item->url = JURI::root() . trim('index.php?option=com_content&view=article&id=' . $item->postid . ':' . $blog->alias); //load content module and position $c_obj = new BlogappContentHelper(); $c_obj->loadContent($item); if (strpos($item->text, 'src="data:image') == false) { if (strpos($item->text, 'href="images')) { $item->introtext = str_replace('href="images', 'href="' . JURI::root() . 'images', $item->introtext); $item->text = str_replace('href="images', 'href="' . JURI::root() . 'images', $item->text); //$item->text = str_replace('src="','src="'.JURI::root(),$item->text); } if (strpos($item->text, 'src="images')) { $item->introtext = str_replace('src="', 'src="' . JURI::root(), $item->introtext); $item->text = str_replace('src="', 'src="' . JURI::root(), $item->text); } if (strpos($item->text, 'src="/')) { $item->introtext = str_replace('src="/', 'src="' . 'http://', $item->introtext); $item->text = str_replace('src="/', 'src="' . 'http://', $item->text); } if (strpos($item->text, 'href="/')) { $item->introtext = str_replace('href="/', 'href="' . 'http://', $item->introtext); $item->text = str_replace('href="/', 'href="' . 'http://', $item->text); } } if (empty($item->image->url)) { $dom = new domDocument(); $dom->loadHTML($item->text); $dom->preserveWhiteSpace = false; $images = $dom->getElementsByTagName('img'); foreach ($images as $img) { $item->image->url = $img->getAttribute('src'); if (!empty($item->image->url)) { break; } } } return $item; }
continue; } $skip = 0; // now we test if (more) results are available if (strstr($htmdata, "/images/yellow_warning.gif")) { echo "No (more) results left{$NL}"; $skip = 1; } if (!$skip) { $len = strlen($htmdata); echo "\t Received {$len} bytes{$NL}"; // Now we parse the html content, putting it into a DOM tree $dom = new domDocument(); $dom->strictErrorChecking = false; $dom->preserveWhiteSpace = true; @$dom->loadHTML($htmdata); $lists = $dom->getElementsByTagName('li'); $num = 0; foreach ($lists as $list) { unset($ar); unset($divs); unset($div); unset($cont); unset($result); unset($tmp); $result['main_keyword'] = $main_keyword; $result['sub_keyword'] = $keyword; $ar = dom2array_full($list); if (count($ar) < 2) { echo "S"; continue;
function retorna_links_endereco_url($codigo_html_site, $endereco_url_site) { // globals ---------------------------------------------------------------- global $numero_maximo_links_pagina; // numero maximo de links por pagina // -------------------------------------------------------------------------- // host principal ------------------------------------------------------ $host_site = retorna_host_url($endereco_url_site); // host do site // -------------------------------------------------------------------------- // array com dados de retorno ---------------------------------- $array_dados_retorno = array(); // array com dados de retorno $array_dados_buffer = array(); // dados de array de buffer temporario // -------------------------------------------------------------------------- // dom com objetos do codigo html ---------------------------- $dom = new domDocument(); // dom com objetos do codigo html // -------------------------------------------------------------------------- // obtendo codigo html de site ------------------------------------ @$dom->loadHTML($codigo_html_site); // obtendo codigo html de site // -------------------------------------------------------------------------- // representa documento html por completo ---------------- $dom->preserveWhiteSpace = false; // representa documento html por completo // -------------------------------------------------------------------------- // obtendo dom por tag -------------------------------------------- $endereco_sites = $dom->getElementsByTagName('a'); // obtendo dom por tag // -------------------------------------------------------------------------- // obtendo links da pagina ---------------------------------------- foreach ($endereco_sites as $url_link_principal) { // endereco url -------------------------------------------------------- $endereco_url = $url_link_principal->getAttribute('href'); // endereco url // -------------------------------------------------------------------------- // endereco url normal, sera usado para verificar se a url nao e null // ---- usado apenas para comparacao de valor nulo! $endereco_url_normal = $url_link_principal->getAttribute('href'); // endereco url normal // -------------------------------------------------------------------------- // verifica se o link esta completo -------------------------------- if (retorna_host_url($endereco_url) == null) { // adiciona protocolo e host de link ------------------------------ $endereco_url = "http://{$host_site}" . $endereco_url; // completa link // ---------------------------------------------------------------------------- } // -------------------------------------------------------------------------- // titulo do link ---------------------------------------------------------- $titulo_link = $url_link_principal->childNodes->item(0)->nodeValue; // titulo do link // -------------------------------------------------------------------------- // endereco host de url de link -------------------------------------- $host_url_link = retorna_host_url($endereco_url); // endereco host de url de link // -------------------------------------------------------------------------- // puxa links de host diferentes ---------------------------------- puxa_links_host_diferente($endereco_url_site, $endereco_url, $titulo_link); // puxa links de host diferentes // ------------------------------------------------------------------------ // atualiza array de retorno ---------------------------------------- if (retorne_elemento_array_existe($array_dados_retorno, $endereco_url) == false and $endereco_url_normal != null and $titulo_link != null and $host_site == $host_url_link) { // atualizando array com links de pagina ---------------------- $array_dados_retorno[$endereco_url] = $titulo_link; // atualizando array com links de pagina // ------------------------------------------------------------------------ } // -------------------------------------------------------------------------- // tamanho do array -------------------------------------------------- $tamanho_array = count($array_dados_retorno); // tamanho do array // -------------------------------------------------------------------------- // verifica se atingiu o tamanho de alocacao maximo ------ if ($tamanho_array > $numero_maximo_links_pagina) { break; // saindo de foreach } // -------------------------------------------------------------------------- } // -------------------------------------------------------------------------- // aloca resultados no buffer -------------------------------------- $array_dados_buffer = $array_dados_retorno; // aloca resultados no buffer // -------------------------------------------------------------------------- // varrendo array de buffer ------------------------------------------ foreach ($array_dados_buffer as $endereco_url_buffer => $titulo_buffer) { // urls de url principal ------------------------------------------------ $sublinks_array = puxar_sublinks($endereco_url_buffer); // urls de url principal // -------------------------------------------------------------------------- // obtendo sublinks e atualizando array de retorno -------- foreach ($sublinks_array as $url_sublink) { // titulo de sublink ---------------------------------------------------- $titulo_sublink = basename($url_sublink); // titulo de sublink // ------------------------------------------------------------------------ // endereco host de url de link -------------------------------------- $host_url_link = retorna_host_url($url_sublink); // endereco host de url de link // -------------------------------------------------------------------------- // puxa links de host diferentes ---------------------------------- puxa_links_host_diferente($endereco_url_site, $url_sublink, $titulo_sublink); // puxa links de host diferentes // ------------------------------------------------------------------------ // atualiza array de retorno ---------------------------------------- if (retorne_elemento_array_existe($array_dados_retorno, $url_sublink) == false and $url_sublink != null and $host_site == $host_url_link) { // atualizando array com links de pagina ------------------------ $array_dados_retorno[$url_sublink] = $titulo_sublink; // atualizando array com links de pagina // ------------------------------------------------------------------------ } // -------------------------------------------------------------------------- } // -------------------------------------------------------------------------- // tamanho do array -------------------------------------------------- $tamanho_array = count($array_dados_retorno); // tamanho do array // -------------------------------------------------------------------------- // verifica se atingiu o tamanho de alocacao maximo ------ if ($tamanho_array > retorne_tamanho_pode_indexar_site()) { break; // saindo de foreach } // -------------------------------------------------------------------------- } // -------------------------------------------------------------------------- // retorno ---------------------------------------------------------------- return $array_dados_retorno; // retorno // -------------------------------------------------------------------------- }
/** * Calculate the page analysis results for post. * * @todo [JRF => whomever] check whether the results of this method are always checked with is_wp_error() * @todo [JRF => whomever] check the usage of this method as it's quite intense/heavy, see if it's only * used when really necessary * @todo [JRF => whomever] see if we can get rid of the passing by reference of $results as it makes * the code obfuscated * * @param object $post Post to calculate the results for. * * @return array|WP_Error */ function calculate_results($post) { $options = WPSEO_Options::get_all(); if (!class_exists('DOMDocument')) { $result = new WP_Error('no-domdocument', sprintf(__("Your hosting environment does not support PHP's %sDocument Object Model%s.", 'wordpress-seo'), '<a href="http://php.net/manual/en/book.dom.php">', '</a>') . ' ' . __("To enjoy all the benefits of the page analysis feature, you'll need to (get your host to) install it.", 'wordpress-seo')); return $result; } if (!is_array($post) && !is_object($post)) { $result = new WP_Error('no-post', __('No post content to analyse.', 'wordpress-seo')); return $result; } elseif (self::get_value('focuskw', $post->ID) === '') { $result = new WP_Error('no-focuskw', sprintf(__('No focus keyword was set for this %s. If you do not set a focus keyword, no score can be calculated.', 'wordpress-seo'), $post->post_type)); self::set_value('linkdex', 0, $post->ID); return $result; } elseif (apply_filters('wpseo_use_page_analysis', true) !== true) { $result = new WP_Error('page-analysis-disabled', sprintf(__('Page Analysis has been disabled.', 'wordpress-seo'), $post->post_type)); return $result; } $results = array(); $job = array(); $sampleurl = $this->get_sample_permalink($post); $job['pageUrl'] = preg_replace('`%(?:post|page)name%`', $sampleurl[1], $sampleurl[0]); $job['pageSlug'] = urldecode($post->post_name); $job['keyword'] = self::get_value('focuskw'); $job['keyword_folded'] = $this->strip_separators_and_fold($job['keyword']); $job['post_id'] = $post->ID; $job['post_type'] = $post->post_type; $dom = new domDocument(); $dom->strictErrorChecking = false; $dom->preserveWhiteSpace = false; /** * Filter: 'wpseo_pre_analysis_post_content' - Make the post content filterable before calculating the page analysis * * @api string $post_content The post content * * @param object $post The post */ $post_content = apply_filters('wpseo_pre_analysis_post_content', $post->post_content, $post); // Check if the post content is not empty if (!empty($post_content)) { @$dom->loadHTML($post_content); } unset($post_content); $xpath = new DOMXPath($dom); // Check if this focus keyword has been used already. $this->check_double_focus_keyword($job, $results); // Keyword $this->score_keyword($job['keyword'], $results); // Title $title = self::get_value('title'); if ($title !== '') { $job['title'] = $title; } else { if (isset($options['title-' . $post->post_type]) && $options['title-' . $post->post_type] !== '') { $title_template = $options['title-' . $post->post_type]; } else { $title_template = '%%title%% - %%sitename%%'; } $job['title'] = wpseo_replace_vars($title_template, $post); } unset($title); $this->score_title($job, $results); // Meta description $description = ''; $desc_meta = self::get_value('metadesc'); if ($desc_meta !== '') { $description = $desc_meta; } elseif (isset($options['metadesc-' . $post->post_type]) && $options['metadesc-' . $post->post_type] !== '') { $description = wpseo_replace_vars($options['metadesc-' . $post->post_type], $post); } unset($desc_meta); self::$meta_length = apply_filters('wpseo_metadesc_length', self::$meta_length, $post); $this->score_description($job, $results, $description, self::$meta_length); unset($description); // Body $body = $this->get_body($post); $firstp = $this->get_first_paragraph($body); $this->score_body($job, $results, $body, $firstp); unset($firstp); // URL $this->score_url($job, $results); // Headings $headings = $this->get_headings($body); $this->score_headings($job, $results, $headings); unset($headings); // Images $imgs = array(); $imgs['count'] = substr_count($body, '<img'); $imgs = $this->get_images_alt_text($post->ID, $body, $imgs); // Check featured image if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { $imgs['count'] += 1; if (empty($imgs['alts'])) { $imgs['alts'] = array(); } $imgs['alts'][] = $this->strtolower_utf8(get_post_meta(get_post_thumbnail_id($post->ID), '_wp_attachment_image_alt', true)); } $this->score_images_alt_text($job, $results, $imgs); unset($imgs); unset($body); // Anchors $anchors = $this->get_anchor_texts($xpath); $count = $this->get_anchor_count($xpath); $this->score_anchor_texts($job, $results, $anchors, $count); unset($anchors, $count, $dom); $results = apply_filters('wpseo_linkdex_results', $results, $job, $post); $this->aasort($results, 'val'); $overall = 0; $overall_max = 0; foreach ($results as $result) { $overall += $result['val']; $overall_max += 9; } if ($overall < 1) { $overall = 1; } $score = wpseo_calc(wpseo_calc($overall, '/', $overall_max), '*', 100, true); if (!is_wp_error($score)) { self::set_value('linkdex', absint($score), $post->ID); $results['total'] = $score; } return $results; }
/** * Build background HTML */ function uncode_get_back_html($background = array(), $overlay_color = '', $overlay_color_alpha = '', $overlay_pattern = '', $type) { global $front_background_colors; $back_color = $back_url = $back_repeat = $back_position = $back_attachment = $back_size = $background_mime = $background_url = $header_background_video = $header_background_selfvideo = $header_overlay_html = $header_overlay_style = $header_overlay_pattern_style = $back_mime_css = $back_html = $content_html = $carousel_html = $overlay_html = ''; $poster_id = $is_carousel = $content_only_text = false; if (!empty($background['background-image'])) { $media_ids = explode(',', $background['background-image']); if (count($media_ids) === 1) { $back_attributes = uncode_get_media_info($background['background-image']); if (isset($back_attributes->post_mime_type)) { $background_mime = $back_attributes->post_mime_type; } $back_repeat = isset($background['background-repeat']) && $background['background-repeat'] !== '' ? 'background-repeat: ' . $background['background-repeat'] . ';' : ''; $back_position = isset($background['background-position']) && $background['background-position'] !== '' ? 'background-position: ' . $background['background-position'] . ';' : ''; $back_attachment = isset($background['background-attachment']) && $background['background-attachment'] !== '' ? 'background-attachment: ' . $background['background-attachment'] . ';' : ''; $back_size = isset($background['background-size']) && $background['background-size'] !== '' ? 'background-size: ' . $background['background-size'] . ';' : ''; if (strpos($background_mime, 'video/') !== false || $background_mime === 'oembed/vimeo' || $background_mime === 'oembed/youtube') { if (wp_is_mobile()) { $background_mime = 'mobile_no_video'; } } if (strpos($background_mime, 'image/') !== false) { $back_metavalues = unserialize($back_attributes->metadata); $image_orig_w = $back_metavalues['width']; $image_orig_h = $back_metavalues['height']; $resized_back = uncode_resize_image($back_attributes->guid, $back_attributes->path, $image_orig_w, $image_orig_h, 12, '', false); $background_url = $resized_back['url']; $back_url = $background_url != '' ? 'background-image: url(' . $background_url . ');' : ''; } else { if (strpos($background_mime, 'video/') !== false) { $videos = array(); $exloded_url = explode(".", strtolower($back_attributes->guid)); $ext = end($exloded_url); $videos[(string) $ext] = $back_attributes->guid; $alt_videos = get_post_meta($background['background-image'], "_uncode_video_alternative", true); if (!empty($alt_videos)) { foreach ($alt_videos as $key => $value) { $exloded_url = explode(".", strtolower($value)); $ext = end($exloded_url); $videos[(string) $ext] = $value; } } else { $videos = array('src' => '"' . $back_attributes->guid . '"'); } $video_src = ''; foreach ($videos as $key => $value) { $video_src .= ' ' . $key . '=' . $value; } $back_mime_css = ' self-video uncode-video-container'; add_filter("wp_video_shortcode_class", "uncode_back_video_class", 10, 2); $header_background_selfvideo = apply_filters('the_content', '[video' . $video_src . ' loop="y"]'); $header_background_selfvideo = str_replace('controls="controls"', '', $header_background_selfvideo); remove_filter("wp_video_shortcode_class", "uncode_back_video_class"); } else { switch ($background_mime) { case 'oembed/flickr': case 'oembed/Imgur': case 'oembed/photobucket': $back_oembed = wp_oembed_get($back_attributes->guid); preg_match_all('/src="([^"]*)"/i', $back_oembed, $img_src); $back_url = isset($img_src[1][0]) ? 'background-image: url(' . str_replace('"', '', $img_src[1][0]) . ');' : ''; if ($background_mime === 'oembed/flickr') { $back_url = str_replace('_n.', '_b.', $back_url); } $background_url = $back_url; $background_mime = 'image'; break; case 'oembed/instagram': $url = 'http://api.instagram.com/oembed?url=' . $back_attributes->guid; $json = wp_remote_fopen($url); $json_data = json_decode($json, true); $background_url = $back_url = $json_data['thumbnail_url']; $back_url = isset($json_data['thumbnail_url']) ? 'background-image: url(' . esc_url($json_data['thumbnail_url']) . ');' : ''; $background_mime = 'image'; break; case 'oembed/vimeo': case 'oembed/youtube': $back_metavalues = unserialize($back_attributes->metadata); $video_orig_w = $back_metavalues['width']; $video_orig_h = $back_metavalues['height']; $video_ratio = $video_orig_h === 0 ? 1.777 : $video_orig_w / $video_orig_h; $header_background_video = ' data-ratio="' . $video_ratio . '" data-provider="' . ($background_mime === 'oembed/vimeo' ? 'vimeo' : 'youtube') . '" data-video="' . $back_attributes->guid . '" data-id="' . rand(10000, 99999) . '"'; $back_mime_css = ' video uncode-video-container'; break; case 'oembed/soundcloud': $url = $back_attributes->guid; $accent_color = $front_background_colors['accent']; $accent_color = str_replace('#', '', $accent_color); $getValues = wp_remote_fopen('http://soundcloud.com/oembed?format=js&url=' . $url . '&iframe=true'); $decodeiFrame = substr($getValues, 1, -2); $decodeiFrame = json_decode($decodeiFrame); preg_match('/src="([^"]+)"/', $decodeiFrame->html, $iframe_src); $iframe_url = str_replace('visual=true', 'visual=false', $iframe_src[1]); $content_html = '<iframe width="100%" scrolling="no" frameborder="no" src="' . $iframe_url . '&color=' . $accent_color . '&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>'; break; case 'oembed/twitter': $url = 'https://api.twitter.com/1/statuses/oembed.json?id=' . basename($back_attributes->guid); $json = wp_remote_fopen($url); $json_data = json_decode($json, true); $id = basename($json_data['url']); $html = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $json_data['html']); $html = str_replace("— ", '', $html); $dom = new domDocument(); $dom->loadHTML($html); $dom->preserveWhiteSpace = false; $twitter_content = $dom->getElementsByTagname('blockquote'); $twitter_blockquote = ''; $twitter_footer = ''; foreach ($twitter_content as $item) { $twitter_content_inner = $item->getElementsByTagname('p'); foreach ($twitter_content_inner as $item_inner) { foreach ($item_inner->childNodes as $child) { $twitter_blockquote .= $child->ownerDocument->saveXML($child); } $item_inner->parentNode->removeChild($item_inner); } foreach ($item->childNodes as $child) { $twitter_footer .= $child->ownerDocument->saveXML($child); } $item->parentNode->removeChild($item); } $content_html = '<div class="twitter-item"> <div class="twitter-item-data"> <blockquote class="tweet-text pullquote"> <p>' . $twitter_blockquote . '</p>'; $content_html .= '<p class="twitter-footer"><small>' . $twitter_footer . '</small></p>'; $content_html .= '</blockquote> </div> </div>'; $poster = get_post_meta($background['background-image'], "_uncode_poster_image", true); if ($poster !== '') { $poster_attributes = uncode_get_media_info($poster); $media_metavalues = unserialize($poster_attributes->metadata); $image_orig_w = $media_metavalues['width']; $image_orig_h = $media_metavalues['height']; $resized_image = uncode_resize_image($poster_attributes->guid, $poster_attributes->path, $image_orig_w, $image_orig_h, 12, '', false); $poster_url = $resized_image['url']; if (isset($poster_attributes->post_mime_type)) { $background_mime = $poster_attributes->post_mime_type; } if (strpos($background_mime, 'image/') !== false) { $background_url = $poster_url; $back_url = $background_url !== '' ? 'background-image: url(' . $background_url . ');' : ''; } else { $back_oembed = wp_oembed_get($poster_attributes->guid); preg_match_all('/src="([^"]*)"/i', $back_oembed, $img_src); $back_url = isset($img_src[1][0]) ? 'background-image: url(' . str_replace('"', '', $img_src[1][0]) . ');' : ''; } $poster_id = $background['background-image']; } $content_only_text = true; break; case 'oembed/html': if (isset($back_attributes->post_excerpt) && $back_attributes->post_excerpt !== '') { $author = '<p><small>' . $back_attributes->post_excerpt . '</small></p>'; } else { $author = ''; } $content_html = '<blockquote class="pullquote"><p>' . $back_attributes->post_content . '</p>' . $author . '</blockquote>'; $poster = get_post_meta($background['background-image'], "_uncode_poster_image", true); if ($poster !== '') { $poster_attributes = uncode_get_media_info($poster); $media_metavalues = unserialize($poster_attributes->metadata); $image_orig_w = $media_metavalues['width']; $image_orig_h = $media_metavalues['height']; $resized_image = uncode_resize_image($poster_attributes->guid, $poster_attributes->path, $image_orig_w, $image_orig_h, 12, '', false); $poster_url = $resized_image['url']; if (isset($poster_attributes->post_mime_type)) { $background_mime = $poster_attributes->post_mime_type; } if (strpos($background_mime, 'image/') !== false) { $background_url = $poster_url; $back_url = $background_url !== '' ? 'background-image: url(' . $background_url . ');' : ''; } else { $back_oembed = wp_oembed_get($poster_attributes->guid); preg_match_all('/src="([^"]*)"/i', $back_oembed, $img_src); $back_url = isset($img_src[1][0]) ? 'background-image: url(' . str_replace('"', '', $img_src[1][0]) . ');' : ''; } $poster_id = $background['background-image']; } $content_only_text = true; break; default: if (strpos($background_mime, 'audio/') !== false) { $content_html = apply_filters('the_content', '[audio src="' . $back_attributes->guid . '"]'); } else { if ($background_mime === 'oembed/spotify') { $content_html = wp_oembed_get($back_attributes->guid); } } $poster = get_post_meta($background['background-image'], "_uncode_poster_image", true); if ($poster !== '') { $poster_attributes = uncode_get_media_info($poster); $media_metavalues = unserialize($poster_attributes->metadata); $image_orig_w = $media_metavalues['width']; $image_orig_h = $media_metavalues['height']; $resized_image = uncode_resize_image($poster_attributes->guid, $poster_attributes->path, $image_orig_w, $image_orig_h, 12, '', false); $poster_url = $resized_image['url']; if (isset($poster_attributes->post_mime_type)) { $background_mime = $poster_attributes->post_mime_type; } if (strpos($background_mime, 'image/') !== false) { $background_url = $poster_url; $back_url = $background_url !== '' ? 'background-image: url(' . $background_url . ');' : ''; } else { $back_oembed = wp_oembed_get($poster_attributes->guid); preg_match_all('/src="([^"]*)"/i', $back_oembed, $img_src); $back_url = isset($img_src[1][0]) ? 'background-image: url(' . str_replace('"', '', $img_src[1][0]) . ');' : ''; } $poster_id = $background['background-image']; } break; } } } } else { $carousel_html = do_shortcode('[vc_gallery el_id="gallery-' . rand() . '" medias="' . $background['background-image'] . '" type="carousel" style_preset="metro" single_padding="0" carousel_fluid="yes" carousel_lg="1" carousel_md="1" carousel_sm="1" gutter_size="0" media_items="media" carousel_interval="0" carousel_dots="yes" carousel_autoh="no" carousel_type="fade" carousel_nav="no" carousel_dots_inside="yes" single_text="overlay" single_border="yes" single_width="12" single_height="12" single_text_visible="no" single_text_anim="no" single_overlay_visible="no" single_overlay_anim="no" single_image_anim="no"]'); $is_carousel = true; } } if (isset($background['background-color']) && $background['background-color'] !== '') { $back_color = ' style-' . $background['background-color'] . '-bg'; } if ($overlay_color !== '') { $overlay_color = ' style-' . $overlay_color . '-bg'; } if ($overlay_color_alpha !== '' && $overlay_color !== '') { $overlay_color_alpha = ' style="opacity: ' . $overlay_color_alpha / 100 . ';"'; } else { $overlay_color_alpha = ''; } if (!empty($overlay_pattern)) { $overlay_pattern = ' uncode-' . $overlay_pattern; } if (!empty($overlay_pattern) && $overlay_pattern !== '') { $header_overlay_pattern_style = '<div class="header-bg-overlay-inner' . $overlay_pattern . '"' . $overlay_color_alpha . '></div>'; } if (!empty($overlay_color) && $overlay_color !== '') { $header_overlay_style = '<div class="header-bg-overlay-inner' . $overlay_color . '"' . $overlay_color_alpha . '></div>'; } if ($header_overlay_style !== '' || $header_overlay_pattern_style !== '') { $header_overlay_html = '<div class="header-bg-overlay">' . $header_overlay_style . $header_overlay_pattern_style . ' </div>'; } $back_image = $back_url != '' || $back_repeat != '' || $back_position != '' || $back_attachment != '' || $back_size != '' ? ' style="' . $back_url . $back_repeat . $back_position . $back_attachment . $back_size . '"' : ''; if ($overlay_color !== '') { $overlay_html = '<div class="block-bg-overlay' . $overlay_color . '"' . $overlay_color_alpha . '></div>'; } if ($type === 'row') { $back_html = '<div class="row-background background-element"' . ($back_mime_css === '' && $header_background_video === '' && $back_image === '' && $header_background_selfvideo === '' && $back_html === '' ? ' style="opacity: 1;"' : '') . '> <div class="background-wrapper"> <div class="background-inner' . $back_mime_css . '"' . $header_background_video . $back_image . '>' . $header_background_selfvideo . $back_html . '</div> ' . $overlay_html . ' </div> </div>'; } else { if ($type === 'column') { $back_html = '<div class="column-background background-element"' . ($back_mime_css === '' && $header_background_video === '' && $back_image === '' && $header_background_selfvideo === '' && $back_html === '' ? ' style="opacity: 1;"' : '') . '> <div class="background-wrapper"> <div class="background-inner' . $back_mime_css . '"' . $header_background_video . $back_image . '>' . $header_background_selfvideo . $back_html . '</div> ' . $overlay_html . ' </div> </div>'; } else { if ($type === 'div') { if ($header_background_video !== '' || $back_image !== '' || $header_background_selfvideo !== '' || $back_html !== '') { $back_html = '<div class="main-background background-element"> <div class="' . $back_mime_css . '"' . $header_background_video . $back_image . '>' . $header_background_selfvideo . $back_html . '</div> </div>'; } } else { if ($overlay_html !== '' || $header_background_video !== '' || $back_image !== '' || $header_background_selfvideo !== '' || $carousel_html !== '') { $back_html = '<div class="header-bg-wrapper"> <div class="header-bg' . $back_mime_css . ($carousel_html !== '' ? ' header-carousel-wrapper' : '') . '"' . $header_background_video . $back_image . '>' . $header_background_selfvideo . $carousel_html . '</div> ' . $overlay_html . ' </div>'; } } } } return array('back_color' => $back_color, 'back_html' => $back_html, 'content_html' => $content_html, 'content_only_text' => $content_only_text, 'back_url' => $background_url, 'poster_id' => $poster_id, 'is_carousel' => $is_carousel, 'mime' => $background_mime); }
/** * Calculate the page analysis results for post. * * @param object $post Post to calculate the results for. * @return array */ function calculate_results($post) { $options = get_wpseo_options(); if (!class_exists('DOMDocument')) { $result = new WP_Error('no-domdocument', sprintf(__("Your hosting environment does not support PHP's %sDocument Object Model%s.", 'wordpress-seo'), '<a href="http://php.net/manual/en/book.dom.php">', '</a>') . ' ' . __("To enjoy all the benefits of the page analysis feature, you'll need to (get your host to) install it.", 'wordpress-seo')); return $result; } if (!wpseo_get_value('focuskw', $post->ID)) { $result = new WP_Error('no-focuskw', sprintf(__('No focus keyword was set for this %s. If you do not set a focus keyword, no score can be calculated.', 'wordpress-seo'), $post->post_type)); wpseo_set_value('linkdex', 0, $post->ID); return $result; } $results = array(); $job = array(); $sampleurl = get_sample_permalink($post); $job["pageUrl"] = preg_replace('/%(post|page)name%/', $sampleurl[1], $sampleurl[0]); $job["pageSlug"] = urldecode($post->post_name); $job["keyword"] = trim(wpseo_get_value('focuskw')); $job["keyword_folded"] = $this->strip_separators_and_fold($job["keyword"]); $job["post_id"] = $post->ID; $dom = new domDocument(); $dom->strictErrorChecking = false; $dom->preserveWhiteSpace = false; @$dom->loadHTML($post->post_content); $xpath = new DOMXPath($dom); $statistics = new Yoast_TextStatistics(); // Check if this focus keyword has been used already. $this->check_double_focus_keyword($job, $results); // Keyword $this->score_keyword($job['keyword'], $results); // Title if (wpseo_get_value('title')) { $job['title'] = wpseo_get_value('title'); } else { if (isset($options['title-' . $post->post_type]) && $options['title-' . $post->post_type] != '') { $title_template = $options['title-' . $post->post_type]; } else { $title_template = '%%title%% - %%sitename%%'; } $job['title'] = wpseo_replace_vars($title_template, (array) $post); } $this->score_title($job, $results, $statistics); // Meta description $description = ''; if (wpseo_get_value('metadesc')) { $description = wpseo_get_value('metadesc'); } else { if (isset($options['metadesc-' . $post->post_type]) && !empty($options['metadesc-' . $post->post_type])) { $description = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post); } } $meta_length = apply_filters('wpseo_metadesc_length', 156, $post); $this->score_description($job, $results, $description, $statistics, $meta_length); unset($description); // Body $body = $this->get_body($post); $firstp = $this->get_first_paragraph($post); $this->score_body($job, $results, $body, $firstp, $statistics); unset($body); unset($firstp); // URL $this->score_url($job, $results, $statistics); // Headings $headings = $this->get_headings($post->post_content); $this->score_headings($job, $results, $headings); unset($headings); // Images $imgs = array(); $imgs['count'] = substr_count($post->post_content, '<img'); $imgs = $this->get_images_alt_text($post, $imgs); $this->score_images_alt_text($job, $results, $imgs); unset($imgs); // Anchors $anchors = $this->get_anchor_texts($xpath); $count = $this->get_anchor_count($xpath); $this->score_anchor_texts($job, $results, $anchors, $count); unset($anchors, $count, $dom); $results = apply_filters('wpseo_linkdex_results', $results, $job, $post); $this->aasort($results, 'val'); $overall = 0; $overall_max = 0; foreach ($results as $result) { $overall += $result['val']; $overall_max += 9; } if ($overall < 1) { $overall = 1; } $score = round($overall / $overall_max * 100); wpseo_set_value('linkdex', absint($score), $post->ID); return $results; }
/** * Finds all <link>-Tags in the passed HTML content, strips them out * and puts them in the internal CSS placeholder store. * You can then retreive them all-in-one with JS::getCode(). * @param string $content - Reference to the HTML content. Note that it * WILL be modified in-place. */ public static function findCSS(&$content) { JS::grabComments($content); //deactivate error handling for not well formed html libxml_use_internal_errors(true); $css = array(); $dom = new domDocument(); $dom->loadHTML($content); libxml_clear_errors(); foreach ($dom->getElementsByTagName('link') as $element) { if (preg_match('/\\.css(\\?.*)?$/', $element->getAttribute('href'))) { $css[] = $element->getAttribute('href'); JS::registerCSS($element->getAttribute('href')); } } JS::restoreComments($content); return $css; }