Esempio n. 1
0
 /**
  * Get a list of the Childs (not recursivly)
  *
  * @return array
  */
 public function getChilds()
 {
     if ($this->childs === null) {
         $list = new Document_List();
         $list->setCondition("parentId = ?", $this->getId());
         $list->setOrderKey("index");
         $list->setOrder("asc");
         $this->childs = $list->load();
     }
     return $this->childs;
 }
 public function seopanelTreeAction()
 {
     $document = Document::getById($this->_getParam("node"));
     $documents = array();
     if ($document->hasChilds()) {
         $list = new Document_List();
         $list->setCondition("parentId = ?", $document->getId());
         $list->setOrderKey("index");
         $list->setOrder("asc");
         $childsList = $list->load();
         foreach ($childsList as $childDocument) {
             // only display document if listing is allowed for the current user
             if ($childDocument->isAllowed("list")) {
                 $list = new Document_List();
                 $list->setCondition("path LIKE ? and type = ?", array($childDocument->getFullPath() . "/%", "page"));
                 if ($childDocument instanceof Document_Page || $list->getTotalCount() > 0) {
                     $nodeConfig = $this->getTreeNodeConfig($childDocument);
                     if (method_exists($childDocument, "getTitle") && method_exists($childDocument, "getDescription")) {
                         $nodeConfig["title"] = $childDocument->getTitle();
                         $nodeConfig["description"] = $childDocument->getDescription();
                         $nodeConfig["title_length"] = strlen($childDocument->getTitle());
                         $nodeConfig["description_length"] = strlen($childDocument->getDescription());
                         // anaylze content
                         $nodeConfig["links"] = 0;
                         $nodeConfig["externallinks"] = 0;
                         $nodeConfig["h1"] = 0;
                         $nodeConfig["h1_text"] = "";
                         $nodeConfig["hx"] = 0;
                         $nodeConfig["imgwithalt"] = 0;
                         $nodeConfig["imgwithoutalt"] = 0;
                         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() . $childDocument->getFullPath();
                             $content = Pimcore_Tool::getHttpData($contentUrl, array("pimcore_preview" => true, "pimcore_admin" => true, "_dc" => time()));
                             if ($content) {
                                 $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);
                                     }
                                     $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"]++;
                                             }
                                         }
                                     }
                                 }
                             }
                         } catch (Exception $e) {
                             Logger::debug($e);
                         }
                         if (strlen($childDocument->getTitle()) > 80 || strlen($childDocument->getTitle()) < 5 || strlen($childDocument->getDescription()) > 180 || strlen($childDocument->getDescription()) < 20 || $nodeConfig["h1"] != 1 || $nodeConfig["hx"] < 1) {
                             $nodeConfig["cls"] = "pimcore_document_seo_warning";
                         }
                     }
                     $documents[] = $nodeConfig;
                 }
             }
         }
     }
     $this->_helper->json($documents);
 }
Esempio n. 3
0
 public function copyInfoAction()
 {
     $transactionId = time();
     $pasteJobs = array();
     $session = new Zend_Session_Namespace("pimcore_copy");
     $session->{$transactionId} = array("idMapping" => array());
     if ($this->_getParam("type") == "recursive" || $this->_getParam("type") == "recursive-update-references") {
         $document = Document::getById($this->_getParam("sourceId"));
         // first of all the new parent
         $pasteJobs[] = array(array("url" => "/admin/document/copy", "params" => array("sourceId" => $this->_getParam("sourceId"), "targetId" => $this->_getParam("targetId"), "type" => "child", "transactionId" => $transactionId, "saveParentId" => true)));
         $childIds = array();
         if ($document->hasChilds()) {
             // get amount of childs
             $list = new Document_List();
             $list->setCondition("path LIKE '" . $document->getFullPath() . "/%'");
             $list->setOrderKey("LENGTH(path)", false);
             $list->setOrder("ASC");
             $childIds = $list->loadIdList();
             if (count($childIds) > 0) {
                 foreach ($childIds as $id) {
                     $pasteJobs[] = array(array("url" => "/admin/document/copy", "params" => array("sourceId" => $id, "targetParentId" => $this->_getParam("targetId"), "sourceParentId" => $this->_getParam("sourceId"), "type" => "child", "transactionId" => $transactionId)));
                 }
             }
         }
         // add id-rewrite steps
         if ($this->_getParam("type") == "recursive-update-references") {
             for ($i = 0; $i < count($childIds) + 1; $i++) {
                 $pasteJobs[] = array(array("url" => "/admin/document/copy-rewrite-ids", "params" => array("transactionId" => $transactionId, "_dc" => uniqid())));
             }
         }
     } else {
         if ($this->_getParam("type") == "child" || $this->_getParam("type") == "replace") {
             // the object itself is the last one
             $pasteJobs[] = array(array("url" => "/admin/document/copy", "params" => array("sourceId" => $this->_getParam("sourceId"), "targetId" => $this->_getParam("targetId"), "type" => $this->_getParam("type"), "transactionId" => $transactionId)));
         }
     }
     $this->_helper->json(array("pastejobs" => $pasteJobs));
 }