/** * @static * @param array $types * @return void */ public static function documents($types = null) { if (empty($types)) { $types = array("page", "snippet", "folder", "link"); } $list = new Document_List(); $list->setCondition("type IN ('" . implode("','", $types) . "')"); self::loadToCache($list); }
public function testCopyAndDeleteDocument() { $documentList = new Document_List(); $documentList->setCondition("`key` like '%_data%' and `type` = 'page'"); $documents = $documentList->load(); $parent = $documents[0]; $this->assertTrue($parent instanceof Document_Page); //remove childs if there are some if ($parent->hasChilds()) { foreach ($parent->getChilds() as $child) { $child->delete(); } } $this->assertFalse($parent->hasChilds()); $service = new Document_Service(User::getById(1)); //copy as child $service->copyAsChild($parent, $parent); $this->assertTrue($parent->hasChilds()); $this->assertTrue(count($parent->getChilds()) == 1); //copy as child no. 2 $service->copyAsChild($parent, $parent); $this->assertTrue($parent->hasChilds()); $this->assertTrue(count($parent->getChilds()) == 2); $childs = $parent->getChilds(); $this->assertTrue(Test_Tool::documentsAreEqual($parent, $childs[0], true)); $this->assertTrue(Test_Tool::documentsAreEqual($parent, $childs[1], true)); //copy recursivley $rootNode = Document::getById(1); $copy = $service->copyRecursive($rootNode, $parent); $this->assertTrue($copy->hasChilds()); $this->assertTrue(count($copy->getChilds()) == 2); $this->assertTrue(Test_Tool::documentsAreEqual($parent, $copy, true)); //create empty document $emptyDoc = Document_Page::create(1, array("userOwner" => 1, "key" => uniqid() . rand(10, 99))); $this->assertFalse(Test_Tool::documentsAreEqual($emptyDoc, $copy, true)); //copy contents $emptyDoc = $service->copyContents($emptyDoc, $copy); $this->assertTrue(Test_Tool::documentsAreEqual($emptyDoc, $copy, true)); //todo copy contents must fail if types differ //delete recusively $shouldBeDeleted[] = $copy->getId(); $childs = $copy->getChilds(); foreach ($childs as $child) { $shouldBeDeleted[] = $child->getId(); } $copy->delete(); foreach ($shouldBeDeleted as $id) { $o = Document::getById($id); $this->assertFalse($o instanceof Document); } }
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); }
/** * 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 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)); }