상속: extends Pimcore\Model\Listing\AbstractListing, implements Zend_Paginator_Adapter_Interface, implements Zend_Paginator_AdapterAggregate, implements Iterator
예제 #1
0
 public function indexAction()
 {
     $list = new Document\Listing();
     $list->setCondition("parentId = ? AND type IN ('link','page')", [$this->document->getId()]);
     $list->load();
     $this->view->documents = $list;
 }
예제 #2
0
 /**
  * @static
  * @param array $types
  * @return void
  */
 public static function documents($types = null)
 {
     if (empty($types)) {
         $types = array("page", "snippet", "folder", "link");
     }
     $list = new Document\Listing();
     $list->setCondition("type IN ('" . implode("','", $types) . "')");
     self::loadToCache($list);
 }
예제 #3
0
 /**
  * @param $parentId
  * @param $languageToAdd
  */
 protected function addDocuments($parentId, $languageToAdd)
 {
     $list = new Listing();
     $list->setCondition('parentId = ?', $parentId);
     $list = $list->load();
     foreach ($list as $document) {
         // Create new document
         $targetParent = \Pimcore\Model\Document::getById(\Multilingual\Document::getDocumentIdInOtherLanguage($document->getParentId(), $languageToAdd));
         /** @var Document_Page $target */
         $target = clone $document;
         $target->id = null;
         $target->setParent($targetParent);
         // Only sync properties when it is allowed
         if (!$target->hasProperty('doNotSyncProperties') && !$document->hasProperty('doNotSyncProperties')) {
             $editableDocumentTypes = array('page', 'email', 'snippet');
             if (in_array($document->getType(), $editableDocumentTypes)) {
                 $target->setContentMasterDocument($document);
             }
             // Set the properties the same
             $sourceProperties = $document->getProperties();
             /** @var string $key
              * @var Property $value
              */
             foreach ($sourceProperties as $key => $value) {
                 if (!$target->hasProperty($key)) {
                     $propertyValue = $value->getData();
                     if ($value->getType() == 'document') {
                         $propertyValue = \Multilingual\Document::getDocumentIdInOtherLanguage($value->getData()->getId(), $languageToAdd);
                     }
                     $target->setProperty($key, $value->getType(), $propertyValue, false, $value->getInheritable());
                 }
             }
         }
         $target->save();
         // Add Link to other languages
         $t = new Keys();
         $t->insert(array("document_id" => $target->getId(), "language" => $languageToAdd, "sourcePath" => $document->getFullPath()));
         // Check for children
         if (count($document->getChilds()) >= 1) {
             // Add the kids
             $this->addDocuments($document->getId(), $languageToAdd);
         }
     }
 }
예제 #4
0
 /**
  * Original function
  * @see Admin_DocumentController::treeGetChildsByIdAction()
  */
 public function treeGetChildsByIdAction()
 {
     $languages = Tool::getValidLanguages();
     $language = $this->_getParam("language", reset($languages));
     $document = Document::getById($this->getParam("node"));
     $documents = array();
     if ($document->hasChilds()) {
         $limit = intval($this->getParam("limit"));
         if (!$this->getParam("limit")) {
             $limit = 100000000;
         }
         $offset = intval($this->getParam("start"));
         $list = new Document\Listing();
         if ($this->getUser()->isAdmin()) {
             $list->setCondition("parentId = ? ", $document->getId());
         } else {
             $userIds = $this->getUser()->getRoles();
             $userIds[] = $this->getUser()->getId();
             $list->setCondition("parentId = ? and\r\n                                        (\r\n                                        (select list from users_workspaces_document where userId in (" . implode(',', $userIds) . ") and LOCATE(CONCAT(path,`key`),cpath)=1  ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\r\n                                        or\r\n                                        (select list from users_workspaces_document where userId in (" . implode(',', $userIds) . ") and LOCATE(cpath,CONCAT(path,`key`))=1  ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\r\n                                        )", $document->getId());
         }
         $list->setOrderKey("index");
         $list->setOrder("asc");
         $list->setLimit($limit);
         $list->setOffset($offset);
         $childsList = $list->load();
         foreach ($childsList as $childDocument) {
             // only display document if listing is allowed for the current user
             if ($childDocument->isAllowed("list")) {
                 if ($childDocument instanceof Document\Page && $childDocument->hasProperty('isLanguageRoot') && $childDocument->getProperty('isLanguageRoot') == 1) {
                     if ($childDocument->getKey() == $language) {
                         //                            $documents[] = $this->getTreeNodeConfig($childDocument);
                         $config = $this->getTreeNodeConfig($childDocument);
                         $config['expanded'] = true;
                         $documents[] = $config;
                     }
                 } else {
                     $documents[] = $this->getTreeNodeConfig($childDocument);
                 }
             }
         }
     }
     if ($this->getParam("limit")) {
         $this->_helper->json(array("offset" => $offset, "limit" => $limit, "total" => $document->getChildAmount($this->getUser()), "nodes" => $documents));
     } else {
         $this->_helper->json($documents);
     }
     $this->_helper->json(false);
 }
예제 #5
0
 /**
  * Find the first active document for a given folder
  *
  * @param $folder_id
  * @return mixed
  */
 protected function findFirstDocumentByParentId($folder_id)
 {
     $list = new Document\Listing();
     $list->setCondition("parentId = ?", (int) $folder_id);
     $list->setOrderKey("index");
     $list->setOrder("asc");
     $list->setLimit(1);
     $childsList = $list->load();
     return reset($childsList);
 }
예제 #6
0
 /**
  * Get a list of the sibling documents
  *
  * @param bool $unpublished
  * @return array
  */
 public function getSiblings($unpublished = false)
 {
     if ($this->siblings === null) {
         $list = new Document\Listing();
         $list->setUnpublished($unpublished);
         // string conversion because parentId could be 0
         $list->addConditionParam("parentId = ?", (string) $this->getParentId());
         $list->addConditionParam("id != ?", $this->getId());
         $list->setOrderKey("index");
         $list->setOrder("asc");
         $this->siblings = $list->load();
     }
     return $this->siblings;
 }
 public function checkPrettyUrlAction()
 {
     $docId = $this->getParam("id");
     $path = trim($this->getParam("path"));
     $path = rtrim($path, "/");
     $success = true;
     // must start with /
     if (strpos($path, "/") !== 0) {
         $success = false;
     }
     if (strlen($path) < 2) {
         $success = false;
     }
     if (!Tool::isValidPath($path)) {
         $success = false;
     }
     $list = new Document\Listing();
     $list->setCondition("(CONCAT(path, `key`) = ? OR id IN (SELECT id from documents_page WHERE prettyUrl = ?))\n            AND id != ?", array($path, $path, $docId));
     if ($list->getTotalCount() > 0) {
         $success = false;
     }
     $this->_helper->json(array("success" => $success));
 }
예제 #8
0
 public function seopanelTreeAction()
 {
     $this->checkPermission("seo_document_editor");
     $document = Document::getById($this->getParam("node"));
     $documents = array();
     if ($document->hasChilds()) {
         $list = new Document\Listing();
         $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\Listing();
                 $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")) {
                         // 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() . $childDocument->getFullPath();
                             $content = Tool::getHttpData($contentUrl, array("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 = $childDocument->getTitle();
                         }
                         if (!$description) {
                             $description = $childDocument->getDescription();
                         }
                         $nodeConfig["title"] = $title;
                         $nodeConfig["description"] = $description;
                         $nodeConfig["title_length"] = mb_strlen($title);
                         $nodeConfig["description_length"] = mb_strlen($description);
                         if (mb_strlen($title) > 80 || mb_strlen($title) < 5 || mb_strlen($description) > 180 || mb_strlen($description) < 20 || $nodeConfig["h1"] != 1 || $nodeConfig["hx"] < 1) {
                             $nodeConfig["cls"] = "pimcore_document_seo_warning";
                         }
                     }
                     $documents[] = $nodeConfig;
                 }
             }
         }
     }
     $this->_helper->json($documents);
 }
예제 #9
0
 /**
  * Event that handles the update of a Document
  *
  * @param $e \Zend_EventManager_Event
  * @throws Exception
  * @throws \Zend_Exception
  */
 public function updateDocument($e)
 {
     // Check if this function is not in progress
     if (\Zend_Registry::isRegistered('Multilingual_' . __FUNCTION__) && \Zend_Registry::get('Multilingual_' . __FUNCTION__) == 1) {
         return;
     }
     // Lock this event-trigger
     \Zend_Registry::set('Multilingual_' . __FUNCTION__, 1);
     /**@var Document\Page $sourceDocument */
     $sourceDocument = $e->getTarget();
     // Get current language
     $sourceLanguage = $sourceDocument->getProperty('language');
     // Get the Source Parent (we have to do it this way, due to a bug in Pimcore)
     $sourceParent = Document::getById($sourceDocument->getParentId());
     // Update SourcePath in Multilingual table
     $t = new Keys();
     $row = $t->fetchRow('document_id = ' . $sourceDocument->getId());
     $t->update(array('sourcePath' => $sourceDocument->getFullPath()), 'sourcePath = "' . $row->sourcePath . '"');
     // Update each language
     $languages = Tool::getValidLanguages();
     foreach ($languages as $language) {
         if ($language != $sourceLanguage) {
             // Find the target document
             /** @var Document $targetDocument */
             $targetDocument = \Multilingual\Document::getDocumentInOtherLanguage($sourceDocument, $language);
             if ($targetDocument) {
                 // Find the parent
                 // If the parent is the root, document, no need to do a lookup
                 if ($sourceParent->getId() == 1) {
                     $targetParent = $sourceParent;
                 } else {
                     $targetParent = \Multilingual\Document::getDocumentInOtherLanguage($sourceParent, $language);
                 }
                 // Only sync properties when it is allowed
                 if (!$targetDocument->hasProperty('doNotSyncProperties') && !$sourceDocument->hasProperty('doNotSyncProperties')) {
                     $typeHasChanged = false;
                     // Set document type (for conversion)
                     if ($targetDocument->getType() != $sourceDocument->getType()) {
                         $typeHasChanged = true;
                         $targetDocument->setType($sourceDocument->getType());
                         if ($targetDocument->getType() == "hardlink" || $targetDocument->getType() == "folder") {
                             // remove navigation settings
                             foreach (["name", "title", "target", "exclude", "class", "anchor", "parameters", "relation", "accesskey", "tabindex"] as $propertyName) {
                                 $targetDocument->removeProperty("navigation_" . $propertyName);
                             }
                         }
                         // overwrite internal store to avoid "duplicate full path" error
                         \Zend_Registry::set("document_" . $targetDocument->getId(), $targetDocument);
                     }
                     // Set the controller the same
                     $editableDocumentTypes = array('page', 'email', 'snippet');
                     if (!$typeHasChanged && in_array($sourceDocument->getType(), $editableDocumentTypes)) {
                         /** @var Document\Page $targetDocument */
                         $targetDocument->setController($sourceDocument->getController());
                         $targetDocument->setAction($sourceDocument->getAction());
                     }
                     // Set the properties the same
                     // But only if they have not been added already
                     $sourceProperties = $sourceDocument->getProperties();
                     /** @var string $key
                      * @var Property $value
                      */
                     foreach ($sourceProperties as $key => $value) {
                         if (strpos($key, 'navigation_') === false) {
                             if (!$targetDocument->hasProperty($key)) {
                                 $propertyValue = $value->getData();
                                 if ($value->getType() == 'document') {
                                     $propertyValue = \Multilingual\Document::getDocumentIdInOtherLanguage($value->getData()->getId(), $language);
                                 }
                                 $targetDocument->setProperty($key, $value->getType(), $propertyValue, false, $value->getInheritable());
                             }
                         }
                     }
                 }
                 // Make sure the parent stays the same
                 $targetDocument->setParent($targetParent);
                 $targetDocument->setParentId($targetParent->getId());
                 $targetDocument->setPath($targetParent->getFullPath() . '/');
                 // Make sure the index stays the same
                 $targetDocument->setIndex($sourceDocument->getIndex());
                 // Make sure the index follows in all the pages at current level
                 $list = new Document\Listing();
                 $list->setCondition("parentId = ? AND id != ?", array($targetParent->getId(), $sourceDocument->getId()));
                 $list->setOrderKey("index");
                 $list->setOrder("asc");
                 $childsList = $list->load();
                 $count = 0;
                 /** @var Document $child */
                 foreach ($childsList as $child) {
                     if ($count == intval($targetDocument->getIndex())) {
                         $count++;
                     }
                     $child->saveIndex($count);
                     $count++;
                 }
                 $targetDocument->save();
             }
         }
     }
     // Unlock this event-trigger
     \Zend_Registry::set('Multilingual_' . __FUNCTION__, 0);
 }
예제 #10
0
파일: Service.php 프로젝트: pimcore/pimcore
 public static function getUniqueKey($item, $nr = 0)
 {
     $list = new Listing();
     $list->setUnpublished(true);
     $key = Element\Service::getValidKey($item->getKey(), "document");
     if (!$key) {
         throw new \Exception("No item key set.");
     }
     if ($nr) {
         $key = $key . '_' . $nr;
     }
     $parent = $item->getParent();
     if (!$parent) {
         throw new \Exception("You have to set a parent document to determine a unique Key");
     }
     if (!$item->getId()) {
         $list->setCondition('parentId = ? AND `key` = ? ', [$parent->getId(), $key]);
     } else {
         $list->setCondition('parentId = ? AND `key` = ? AND id != ? ', [$parent->getId(), $key, $item->getId()]);
     }
     $check = $list->loadIdList();
     if (!empty($check)) {
         $nr++;
         $key = self::getUniqueKey($item, $nr);
     }
     return $key;
 }
예제 #11
0
 public function seopanelTreeAction()
 {
     $this->checkPermission("seo_document_editor");
     $document = Document::getById($this->getParam("node"));
     $documents = [];
     if ($document->hasChilds()) {
         $list = new Document\Listing();
         $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\Listing();
                 $list->setCondition("path LIKE ? and type = ?", [$childDocument->getRealFullPath() . "/%", "page"]);
                 if ($childDocument instanceof Document\Page || $list->getTotalCount() > 0) {
                     $documents[] = $this->getSeoNodeConfig($childDocument);
                 }
             }
         }
     }
     $this->_helper->json($documents);
 }