Admin_DocumentController::getSeoNodeConfig PHP Method

getSeoNodeConfig() private method

private getSeoNodeConfig ( $document )
    private function getSeoNodeConfig($document)
    {
        $nodeConfig = $this->getTreeNodeConfig($document);
        if (method_exists($document, "getTitle") && method_exists($document, "getDescription")) {
            // anaylze content
            $nodeConfig["links"] = 0;
            $nodeConfig["externallinks"] = 0;
            $nodeConfig["h1"] = 0;
            $nodeConfig["h1_text"] = "";
            $nodeConfig["hx"] = 0;
            $nodeConfig["imgwithalt"] = 0;
            $nodeConfig["imgwithoutalt"] = 0;
            $title = null;
            $description = null;
            try {
                // cannot use the rendering service from Document\Service::render() because of singleton's ...
                // $content = Document\Service::render($childDocument, array("pimcore_admin" => true, "pimcore_preview" => true), true);
                $request = $this->getRequest();
                $contentUrl = $request->getScheme() . "://" . $request->getHttpHost() . $document->getFullPath();
                $content = Tool::getHttpData($contentUrl, ["pimcore_preview" => true, "pimcore_admin" => true, "_dc" => time()]);
                if ($content) {
                    include_once "simple_html_dom.php";
                    $html = str_get_html($content);
                    if ($html) {
                        $nodeConfig["links"] = count($html->find("a"));
                        $nodeConfig["externallinks"] = count($html->find("a[href^=http]"));
                        $nodeConfig["h1"] = count($html->find("h1"));
                        $h1 = $html->find("h1", 0);
                        if ($h1) {
                            $nodeConfig["h1_text"] = strip_tags($h1->innertext);
                        }
                        $title = $html->find("title", 0);
                        if ($title) {
                            $title = html_entity_decode(trim(strip_tags($title->innertext)), null, "UTF-8");
                        }
                        $description = $html->find("meta[name=description]", 0);
                        if ($description) {
                            $description = html_entity_decode(trim(strip_tags($description->content)), null, "UTF-8");
                        }
                        $nodeConfig["hx"] = count($html->find("h2,h2,h4,h5"));
                        $images = $html->find("img");
                        if ($images) {
                            foreach ($images as $image) {
                                $alt = $image->alt;
                                if (empty($alt)) {
                                    $nodeConfig["imgwithoutalt"]++;
                                } else {
                                    $nodeConfig["imgwithalt"]++;
                                }
                            }
                        }
                        $html->clear();
                        unset($html);
                    }
                }
            } catch (\Exception $e) {
                Logger::debug($e);
            }
            if (!$title) {
                $title = $document->getTitle();
            }
            if (!$description) {
                $description = $document->getDescription();
            }
            $nodeConfig["title"] = $title;
            $nodeConfig["description"] = $description;
            $nodeConfig["title_length"] = mb_strlen($title);
            $nodeConfig["description_length"] = mb_strlen($description);
            $qtip = "";
            /** @var \Zend_Translate_Adapter $t */
            $t = \Zend_Registry::get("Zend_Translate");
            if (mb_strlen($title) > 80) {
                $nodeConfig["cls"] = "pimcore_document_seo_warning";
                $qtip .= $t->translate("The title is too long, it should have 5 to 80 characters.<br>");
            }
            if (mb_strlen($title) < 5) {
                $nodeConfig["cls"] = "pimcore_document_seo_warning";
                $qtip .= $t->translate("The title is too short, it should have 5 to 80 characters.<br>");
            }
            if (mb_strlen($description) > 180) {
                $nodeConfig["cls"] = "pimcore_document_seo_warning";
                $qtip .= $t->translate("The description is too long, it should have 20 to 180 characters.<br>");
            }
            if (mb_strlen($description) < 20) {
                $nodeConfig["cls"] = "pimcore_document_seo_warning";
                $qtip .= $t->translate("The description is too short, it should have 20 to 180 characters.<br>");
            }
            if ($nodeConfig["h1"] != 1) {
                $nodeConfig["cls"] = "pimcore_document_seo_warning";
                $qtip .= sprintf($t->translate("The document should have one h1, but has %s.<br>"), $nodeConfig["h1"]);
            }
            if ($nodeConfig["hx"] < 1) {
                $nodeConfig["cls"] = "pimcore_document_seo_warning";
                $qtip .= $t->translate("The document should some headlines other than h1, but has none.<br>");
            }
            if ($qtip) {
                $nodeConfig["qtip"] = $qtip;
            }
        }
        return $nodeConfig;
    }