public function run($type, $id, $contentKey = null, $user) { if (isset($_FILES['avatar'])) { $type = trim($type); $folder = str_replace(DIRECTORY_SEPARATOR, "/", DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR); $pathImage = $this->processImage($_FILES['avatar'], $id, $type); if ($pathImage) { $params = array(); $params["id"] = $id; $params["type"] = $type; $params['folder'] = $folder; $params['moduleId'] = Yii::app()->controller->module->id; $params['name'] = $pathImage["name"]; $params['doctype'] = "image"; $params['size'] = $pathImage["size"][0] * $pathImage["size"][1] / 1000; $params['author'] = $user; $params['category'] = array(); $params['contentKey'] = $contentKey; $result = Document::save($params); //Profile to check $urlBdd = str_replace(DIRECTORY_SEPARATOR, "/", DIRECTORY_SEPARATOR . "upload" . DIRECTORY_SEPARATOR . Yii::app()->controller->module->id . $folder . $pathImage["name"]); Document::setImagePath($id, $type, $urlBdd, $contentKey); $newImage = Document::getById($result["id"]); } $res = array('result' => true, 'msg' => 'The picture was uploaded', 'imagePath' => $urlBdd, "id" => $result["id"], "image" => $newImage); Rest::json($res); Yii::app()->end(); } }
/** * @return Document_PageSnippet */ public function getSourceDocument() { if ($this->getSourceId()) { return Document::getById($this->getSourceId()); } return null; }
/** * Loads a list of entries for the specicifies parameters, returns an array of Search_Backend_Data * * @return array */ public function load() { $entries = array(); $data = $this->db->fetchAll("SELECT * FROM search_backend_data" . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); foreach ($data as $entryData) { if ($entryData['maintype'] == 'document') { $element = Document::getById($entryData['id']); } else { if ($entryData['maintype'] == 'asset') { $element = Asset::getById($entryData['id']); } else { if ($entryData['maintype'] == 'object') { $element = Object_Abstract::getById($entryData['id']); } else { Logger::err("unknown maintype "); } } } if ($element) { $entry = new Search_Backend_Data(); $entry->setId(new Search_Backend_Data_Id($element)); $entry->setFullPath($entryData['fullpath']); $entry->setType($entryData['type']); $entry->setSubtype($entryData['subtype']); $entry->setUserOwner($entryData['userowner']); $entry->setUserModification($entryData['usermodification']); $entry->setCreationDate($entryData['creationdate']); $entry->setModificationDate($entryData['modificationdate']); $entry->setPublished($entryData['published'] === 0 ? false : true); $entries[] = $entry; } } $this->model->setEntries($entries); return $entries; }
/** * @static * @param $element * @return string */ public static function getIdPathForElement($element) { $path = ""; if ($element instanceof Document) { $nid = $element->getParentId(); $ne = Document::getById($nid); } else { if ($element instanceof Asset) { $nid = $element->getParentId(); $ne = Asset::getById($nid); } else { if ($element instanceof Object_Abstract) { $nid = $element->getO_parentId(); $ne = Object_Abstract::getById($nid); } } } if ($ne) { $path = self::getIdPathForElement($ne, $path); } if ($element) { $path = $path . "/" . $element->getId(); } return $path; }
/** * Loads a list of objects (all are an instance of Document) for the given parameters an return them * * @return array */ public function load() { $documents = array(); $documentsData = $this->db->fetchAll("SELECT id,type FROM documents" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); foreach ($documentsData as $documentData) { if ($documentData["type"]) { $documents[] = Document::getById($documentData["id"]); } } $this->model->setDocuments($documents); return $documents; }
public function getNavigation($activeDocument, $navigationRootDocument = null, $htmlMenuIdPrefix = null) { $this->_activeDocument = $activeDocument; $this->_htmlMenuIdPrefix = $htmlMenuIdPrefix; $this->_navigationContainer = new Zend_Navigation(); if (!$navigationRootDocument) { $navigationRootDocument = Document::getById(1); } if ($navigationRootDocument->hasChilds()) { $this->buildNextLevel($navigationRootDocument, null, true); } return $this->_navigationContainer; }
public function load($override = false) { if ($this->search_result_items !== null && !$override) { return $this->search_result_items; } $search_result = $this->getDocumentIds(); $sliced = array_slice($search_result, $this->offset, $this->limit, true); $documents = array(); foreach ($sliced as $id) { $document = Document::getById($id); $documents[] = $document; } $this->search_result_items = $documents; return $this->search_result_items; }
public function exportAction() { try { $documentId = $this->getParam("documentId"); $document = Document::getById($documentId); $exportFile = PimPon_Document_Export::doExport($document); ob_end_clean(); header("Content-type: application/json"); header("Content-Disposition: attachment; filename=\"pimponexport.documents." . $document->getKey() . ".json\""); echo file_get_contents($exportFile); exit; } catch (Exception $ex) { Logger::err($ex->getMessage()); $this->_helper->json(array("success" => false, "data" => 'error'), false); } }
/** * Get the data for the object from database for the given id * @param integer $id * @return void */ public function getById($id) { $data = $this->db->fetchRow("SELECT * FROM notes WHERE id = ?", $id); if (!$data["id"]) { throw new Exception("Note item with id " . $id . " not found"); } $this->assignVariablesToModel($data); // get key-value data $keyValues = $this->db->fetchAll("SELECT * FROM notes_data WHERE id = ?", $id); $preparedData = array(); foreach ($keyValues as $keyValue) { $data = $keyValue["data"]; $type = $keyValue["type"]; $name = $keyValue["name"]; if ($type == "document") { if ($data) { $data = Document::getById($data); } } else { if ($type == "asset") { if ($data) { $data = Asset::getById($data); } } else { if ($type == "object") { if ($data) { $data = Object_Abstract::getById($data); } } else { if ($type == "date") { if ($data > 0) { $data = new Zend_Date($data); } } else { if ($type == "bool") { $data = (bool) $data; } } } } } $preparedData[$name] = array("data" => $data, "type" => $type); } $this->model->setData($preparedData); }
public function run($dir, $type) { $filepath = Yii::app()->params['uploadDir'] . $dir . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $_POST['parentId'] . DIRECTORY_SEPARATOR . $_POST['name']; if (isset(Yii::app()->session["userId"]) && file_exists($filepath)) { if (unlink($filepath)) { Document::removeDocumentById($_POST['docId']); echo json_encode(array('result' => true, "msg" => Yii::t("document", "Document deleted"))); } else { echo json_encode(array('result' => false, 'error' => Yii::t("common", "Something went wrong!"), "filepath" => $filepath)); } } else { $doc = Document::getById($_POST['docId']); if ($doc) { Document::removeDocumentById($_POST['docId']); } echo json_encode(array('result' => false, 'error' => Yii::t("common", "Something went wrong!"), "filepath" => $filepath)); } }
protected function _handleError(Zend_Controller_Request_Abstract $request) { // remove zend error handler $front = Zend_Controller_Front::getInstance(); $front->unregisterPlugin("Zend_Controller_Plugin_ErrorHandler"); $response = $this->getResponse(); if ($response->isException() && !$this->_isInsideErrorHandlerLoop) { // get errorpage try { // enable error handler $front->setParam('noErrorHandler', false); $siteKey = Pimcore_Tool_Frontend::getSiteKey(); $errorPath = Pimcore_Config::getSystemConfig()->documents->error_pages->{$siteKey}; if (empty($errorPath)) { $errorPath = "/"; } $document = Document::getByPath($errorPath); if (!$document instanceof Document_Page) { // default is home $document = Document::getById(1); } if ($document instanceof Document_Page) { $params = Pimcore_Tool::getRoutingDefaults(); if ($module = $document->getModule()) { $params["module"] = $module; } if ($controller = $document->getController()) { $params["controller"] = $controller; $params["action"] = "index"; } if ($action = $document->getAction()) { $params["action"] = $action; } $this->setErrorHandler($params); $request->setParam("document", $document); Zend_Registry::set("pimcore_error_document", $document); } } catch (Exception $e) { Logger::emergency("error page not found"); } } // call default ZF error handler parent::_handleError($request); }
/** * @param int $targetId */ public function setTargetId($targetId) { $this->targetId = $targetId; try { if ($this->type == "object") { $this->target = Object_Abstract::getById($targetId); } else { if ($this->type == "asset") { $this->target = Asset::getById($targetId); } else { if ($this->type == "document") { $this->target = Document::getById($targetId); } else { Logger::log(get_class($this) . ": could not set resource - unknown type[" . $this->type . "]"); } } } } catch (Exception $e) { Logger::log(get_class($this) . ": Error setting resource"); } }
public function commentsAction() { if ($this->_getParam('xaction') == "destroy") { $id = $this->_getParam("comments"); $id = str_replace('"', '', $id); RatingsComments_Plugin::deleteComment($id); $results["success"] = true; $results["comments"] = ""; } else { $id = $this->_getParam("objectid"); $type = $this->_getParam("type"); if ($type == "object") { $target = Object_Abstract::getById($id); } else { if ($type == "page" || $type == "snippet") { $target = Document::getById($id); } else { //try asset $target = Asset::getById($id); } } $comments = RatingsComments_Plugin::getComments($target); $results = array(); if (is_array($comments)) { foreach ($comments as $comment) { $shorttext = $comment->getComment(); if (strlen($shorttext) > 50) { $shorttext = substr($shorttext, 0, 50) . "..."; } $results["comments"][] = array("c_id" => $comment->getId(), "c_shorttext" => $shorttext, "c_text" => $comment->getComment(), "c_rating" => $comment->getRating(), "c_user" => $comment->getName(), "c_created" => $comment->getDate()); } } if (!isset($results["comments"])) { $results["comments"] = ""; } } echo Zend_Json::encode($results); $this->removeViewRenderer(); }
/** * change general user permissions * @depends testModifyUserToAdmin * @var User $user */ public function testPermissionChanges() { $userGroup = User::getByName("unitTestUserGroup"); $username = $userGroup->getUsername(); $userGroup->setAdmin(false); $userGroup->save(); unset($userGroup); $userGroup = User::getByName($username); //test if admin is allowed all $permissionList = new User_Permission_Definition_List(); $permissionList->load(); $permissions = $permissionList->getDefinitions(); $setPermissions = array(); //gradually set all system permissions foreach ($permissions as $permission) { $userGroup->setPermission($permission->getKey()); $setPermissions[] = $permission->getKey(); $userGroup->save(); unset($userGroup); $userGroup = User::getByName($username); foreach ($setPermissions as $p) { $this->assertTrue($userGroup->isAllowed($p)); } } //remove system permissions $userGroup->setAllAclToFalse(); foreach ($setPermissions as $p) { $this->assertFalse($userGroup->isAllowed($p)); } //cannot list documents, assts, objects because no permissions by now $documentRoot = Document::getById(1); $documentRoot->getPermissionsForUser($userGroup); $this->assertFalse($documentRoot->isAllowed("list")); $objectRoot = Object_Abstract::getById(1); $objectRoot->getPermissionsForUser($userGroup); $this->assertFalse($objectRoot->isAllowed("list")); $assetRoot = Asset::getById(1); $assetRoot->getPermissionsForUser($userGroup); $this->assertFalse($assetRoot->isAllowed("list")); $objectFolder = new Object_Folder(); $objectFolder->setParentId(1); $objectFolder->setUserOwner(1); $objectFolder->setUserModification(1); $objectFolder->setCreationDate(time()); $objectFolder->setKey(uniqid() . rand(10, 99)); $objectFolder->save(); $documentFolder = Document_Folder::create(1, array("userOwner" => 1, "key" => uniqid() . rand(10, 99))); $assetFolder = Asset_Folder::create(1, array("filename" => uniqid() . "_data", "type" => "folder", "userOwner" => 1)); $user = User::getByName("unitTestUser"); $user->setAdmin(false); $user->save(); $userGroup->setPermission("objects"); $userGroup->setPermission("documents"); $userGroup->setPermission("assets"); $userGroup->save(); //test permissions with user group and user $this->permissionTest($objectRoot, $objectFolder, $userGroup, $user, $user, "object"); $this->permissionTest($assetRoot, $assetFolder, $userGroup, $user, $user, "asset"); $this->permissionTest($documentRoot, $documentFolder, $userGroup, $user, $user, "document"); //test permissions when there is no user group permissions $user = User::create(array("parentId" => 0, "username" => "unitTestUser2", "password" => md5("unitTestUser2"), "hasCredentials" => true, "active" => true)); unset($user); $user = User::getByName("unitTestUser2"); $user->setPermission("objects"); $user->setPermission("documents"); $user->setPermission("assets"); $user->save(); $this->assertTrue($user instanceof User and $user->getUsername() == "unitTestUser2"); $this->permissionTest($objectRoot, $objectFolder, null, $user, $user, "object"); $this->permissionTest($assetRoot, $assetFolder, null, $user, $user, "asset"); $this->permissionTest($documentRoot, $documentFolder, null, $user, $user, "document"); //test permissions when there is only user group permissions $user = User::create(array("parentId" => $userGroup->getId(), "username" => "unitTestUser3", "password" => md5("unitTestUser3"), "hasCredentials" => true, "active" => true)); unset($user); $user = User::getByName("unitTestUser3"); $this->assertTrue($user instanceof User and $user->getUsername() == "unitTestUser3"); $this->permissionTest($objectRoot, $objectFolder, $userGroup, null, $user, "object"); $this->permissionTest($assetRoot, $assetFolder, $userGroup, null, $user, "asset"); $this->permissionTest($documentRoot, $documentFolder, $userGroup, null, $user, "document"); }
/** * Returns the current tag's data for web service export * * @abstract * @return array */ public function getForWebserviceExport() { $el = parent::getForWebserviceExport(); if ($this->data["internal"]) { if (intval($this->data["internalId"]) > 0) { if ($this->data["internalType"] == "document") { $referencedDocument = Document::getById($this->data["internalId"]); if (!$referencedDocument instanceof Document) { //detected broken link $document = Document::getById($this->getDocumentId()); Element_Service::scheduleForSanityCheck($document); } } else { if ($this->data["internalType"] == "asset") { $referencedAsset = Asset::getById($this->data["internalId"]); if (!$referencedAsset instanceof Asset) { //detected broken link $document = Document::getById($this->getDocumentId()); Element_Service::scheduleForSanityCheck($document); } } } } } $el->data = $this->data; return $el; }
/** * @return void */ public function setObjectFromId() { if ($this->internalType == "document") { $this->object = Document::getById($this->internal); } else { if ($this->internalType == "asset") { $this->object = Asset::getById($this->internal); } } return $this->object; }
public function init() { parent::init(); // log exceptions if handled by error_handler $this->checkForErrors(); // general definitions Pimcore::unsetAdminMode(); Document::setHideUnpublished(true); Object_Abstract::setHideUnpublished(true); Object_Abstract::setGetInheritedValues(true); // contains the logged in user if necessary $user = null; // assign variables $this->view->controller = $this; // init website config $config = Pimcore_Config::getWebsiteConfig(); $this->config = $config; $this->view->config = $config; if (!$this->_getParam("document")) { Zend_Registry::set("pimcore_editmode", false); $this->editmode = false; $this->view->editmode = false; // no document available, continue, ... return; } else { $this->setDocument($this->_getParam("document")); } if ($this->_getParam("pimcore_editmode") || $this->_getParam("pimcore_version") || $this->_getParam("pimcore_preview") || $this->_getParam("pimcore_admin") || $this->_getParam("pimcore_object_preview")) { $specialAdminRequest = true; $this->disableBrowserCache(); // start admin session & get logged in user $user = Pimcore_Tool_Authentication::authenticateSession(); } if (!$this->document->isPublished()) { if ($specialAdminRequest) { if (!$user) { throw new Exception("access denied for " . $this->document->getFullPath()); } } else { throw new Exception("access denied for " . $this->document->getFullPath()); } } // register global locale if the document has the system property "language" if ($this->document->getProperty("language")) { $locale = new Zend_Locale($this->document->getProperty("language")); Zend_Registry::set('Zend_Locale', $locale); $this->getResponse()->setHeader("Content-Language", strtolower(str_replace("_", "-", (string) $locale)), true); } // for editmode if ($user) { if ($this->_getParam("pimcore_editmode") and !Zend_Registry::isRegistered("pimcore_editmode")) { Zend_Registry::set("pimcore_editmode", true); // check if there is the document in the session $docKey = "document_" . $this->getDocument()->getId(); $docSession = new Zend_Session_Namespace("pimcore_documents"); if ($docSession->{$docKey}) { // if there is a document in the session use it $this->setDocument($docSession->{$docKey}); } else { // set the latest available version for editmode if there is no doc in the session $latestVersion = $this->getDocument()->getLatestVersion(); if ($latestVersion) { $latestDoc = $latestVersion->loadData(); if ($latestDoc instanceof Document_PageSnippet) { $this->setDocument($latestDoc); } } } // register editmode plugin $front = Zend_Controller_Front::getInstance(); $front->registerPlugin(new Pimcore_Controller_Plugin_Frontend_Editmode($this), 1000); } else { Zend_Registry::set("pimcore_editmode", false); } } else { Zend_Registry::set("pimcore_editmode", false); } // for preview if ($user) { // document preview if ($this->_getParam("pimcore_preview")) { // get document from session $docKey = "document_" . $this->_getParam("document")->getId(); $docSession = new Zend_Session_Namespace("pimcore_documents"); if ($docSession->{$docKey}) { $this->setDocument($docSession->{$docKey}); } } // object preview if ($this->_getParam("pimcore_object_preview")) { $key = "object_" . $this->_getParam("pimcore_object_preview"); $session = new Zend_Session_Namespace("pimcore_objects"); if ($session->{$key}) { $object = $session->{$key}; // add the object to the registry so every call to Object_Abstract::getById() will return this object instead of the real one Zend_Registry::set("object_" . $object->getId(), $object); } } } // for version preview if ($this->_getParam("pimcore_version")) { if ($user) { // only get version data at the first call || because of embedded Snippets ... if (!Zend_Registry::isRegistered("pimcore_version_active")) { $version = Version::getById($this->_getParam("pimcore_version")); $this->setDocument($version->getData()); Zend_Registry::set("pimcore_version_active", true); } } } // for public versions if ($this->_getParam("v")) { try { $version = Version::getById($this->_getParam("v")); if ($version->getPublic()) { $this->setDocument($version->getData()); } } catch (Exception $e) { } } // check if document is a wrapped hardlink, if this is the case send a rel=canonical header to the source document if ($this->getDocument() instanceof Document_Hardlink_Wrapper_Interface) { // get the cononical (source) document $hardlinkCanonicalSourceDocument = Document::getById($this->getDocument()->getId()); $request = $this->getRequest(); $this->getResponse()->setHeader("Link", '<' . $request->getScheme() . "://" . $request->getHttpHost() . $hardlinkCanonicalSourceDocument->getFullPath() . '>; rel="canonical"'); } // set some parameters $this->editmode = Zend_Registry::get("pimcore_editmode"); $this->view->editmode = Zend_Registry::get("pimcore_editmode"); }
/** * */ public function dispatchLoopShutdown() { if (!Tool::isHtmlResponse($this->getResponse())) { return; } if ($this->enabled) { $targets = array(); $personas = array(); $dataPush = array("personas" => $this->personas, "method" => strtolower($this->getRequest()->getMethod())); if (count($this->events) > 0) { $dataPush["events"] = $this->events; } if ($this->document instanceof Document\Page && !Model\Staticroute::getCurrentRoute()) { $dataPush["document"] = $this->document->getId(); if ($this->document->getPersonas()) { if ($_GET["_ptp"]) { // if a special version is requested only return this id as target group for this page $dataPush["personas"][] = (int) $_GET["_ptp"]; } else { $docPersonas = explode(",", trim($this->document->getPersonas(), " ,")); // cast the values to int array_walk($docPersonas, function (&$value) { $value = (int) trim($value); }); $dataPush["personas"] = array_merge($dataPush["personas"], $docPersonas); } } // check for persona specific variants of this page $personaVariants = array(); foreach ($this->document->getElements() as $key => $tag) { if (preg_match("/^persona_-([0-9]+)-_/", $key, $matches)) { $id = (int) $matches[1]; if (Model\Tool\Targeting\Persona::isIdActive($id)) { $personaVariants[] = $id; } } } if (!empty($personaVariants)) { $personaVariants = array_values(array_unique($personaVariants)); $dataPush["personaPageVariants"] = $personaVariants; } } // no duplicates $dataPush["personas"] = array_unique($dataPush["personas"]); $activePersonas = array(); foreach ($dataPush["personas"] as $id) { if (Model\Tool\Targeting\Persona::isIdActive($id)) { $activePersonas[] = $id; } } $dataPush["personas"] = $activePersonas; if ($this->document) { // @TODO: cache this $list = new Model\Tool\Targeting\Rule\Listing(); $list->setCondition("active = 1"); foreach ($list->load() as $target) { $redirectUrl = $target->getActions()->getRedirectUrl(); if (is_numeric($redirectUrl)) { $doc = \Document::getById($redirectUrl); if ($doc instanceof \Document) { $target->getActions()->redirectUrl = $doc->getFullPath(); } } $targets[] = $target; } $list = new Model\Tool\Targeting\Persona\Listing(); $list->setCondition("active = 1"); foreach ($list->load() as $persona) { $personas[] = $persona; } } $code = '<script type="text/javascript" src="/pimcore/static/js/frontend/geoip.js/"></script>'; $code .= '<script type="text/javascript">'; $code .= 'var pimcore = pimcore || {};'; $code .= 'pimcore["targeting"] = {};'; $code .= 'pimcore["targeting"]["dataPush"] = ' . \Zend_Json::encode($dataPush) . ';'; $code .= 'pimcore["targeting"]["targetingRules"] = ' . \Zend_Json::encode($targets) . ';'; $code .= 'pimcore["targeting"]["personas"] = ' . \Zend_Json::encode($personas) . ';'; $code .= '</script>'; $code .= '<script type="text/javascript" src="/pimcore/static/js/frontend/targeting.js"></script>'; $code .= "\n"; // analytics $body = $this->getResponse()->getBody(); // search for the end <head> tag, and insert the google analytics code before // this method is much faster than using simple_html_dom and uses less memory $headEndPosition = stripos($body, "<head>"); if ($headEndPosition !== false) { $body = substr_replace($body, "<head>\n" . $code, $headEndPosition, 7); } $this->getResponse()->setBody($body); } }
<!--[if IE 9]><html class="ie9 no-js" lang="en"><![endif]--> <!--[if !IE]><!--> <html lang="en" class="no-js"> <!--<![endif]--> <!-- start: HEAD --> <head> <?php // portal detection => portal needs an adapted version of the layout $isPortal = false; if ($this->getParam("controller") == "content" && $this->getParam("action") == "portal") { $isPortal = true; } // output the collected meta-data if (!$this->document) { // use "home" document as default if no document is present $this->document = Document::getById(1); } if ($this->document->getTitle()) { // use the manually set title if available $this->headTitle()->set($this->document->getTitle()); } if ($this->document->getDescription()) { // use the manually set description if available $this->headMeta()->appendName('description', $this->document->getDescription()); } $this->headTitle()->append("pimcore Demo"); $this->headTitle()->setSeparator(" : "); echo $this->headTitle(); echo $this->headMeta(); ?>
/** * @static * @param string $type * @param int $id * @return Element_Interface */ public static function getElementById($type, $id) { $element = null; if ($type == "asset") { $element = Asset::getById($id); } else { if ($type == "object") { $element = Object_Abstract::getById($id); } else { if ($type == "document") { $element = Document::getById($id); } } } return $element; }
/** * @deprecated * @static * @param array $idMapping e.g. array("asset"=>array(OLD_ID=>NEW_ID),"object"=>array(OLD_ID=>NEW_ID),"document"=>array(OLD_ID=>NEW_ID)); * @param string $text html text of wysiwyg field * @return mixed */ public static function replaceWysiwygTextRelationIds($idMapping, $text) { if (!empty($text)) { $html = str_get_html($text); if (!$html) { return $text; } $s = $html->find("a[pimcore_id],img[pimcore_id]"); foreach ($s as $el) { // image if ($el->src) { $type = "asset"; } // link if ($el->href) { if ($el->pimcore_type == "asset") { $type = "asset"; } else { if ($el->pimcore_type == "document") { $type = "document"; } } } $newId = $idMapping[$type][$el->attr["pimcore_id"]]; if ($newId) { //update id if ($type == "asset") { $pimcoreElement = Asset::getById($newId); } else { $pimcoreElement = Document::getById($newId); } $el->pimcore_id = $newId; $el->src = $pimcoreElement->getFullPath(); } else { //remove relation, not found in mapping $el->pimcore_id = null; $el->src = null; } } return $html->save(); } }
public function glossaryAction() { if ($this->_getParam("data")) { if ($this->getUser()->isAllowed("glossary")) { Pimcore_Model_Cache::clearTag("glossary"); if ($this->_getParam("xaction") == "destroy") { $id = Zend_Json::decode($this->_getParam("data")); $glossary = Glossary::getById($id); $glossary->delete(); $this->_helper->json(array("success" => true, "data" => array())); } else { if ($this->_getParam("xaction") == "update") { $data = Zend_Json::decode($this->_getParam("data")); // save glossary $glossary = Glossary::getById($data["id"]); if ($data["link"]) { if ($doc = Document::getByPath($data["link"])) { $tmpLink = $data["link"]; $data["link"] = $doc->getId(); } } $glossary->setValues($data); $glossary->save(); if ($link = $glossary->getLink()) { if (intval($link) > 0) { if ($doc = Document::getById(intval($link))) { $glossary->setLink($doc->getFullPath()); } } } $this->_helper->json(array("data" => $glossary, "success" => true)); } else { if ($this->_getParam("xaction") == "create") { $data = Zend_Json::decode($this->_getParam("data")); unset($data["id"]); // save glossary $glossary = new Glossary(); if ($data["link"]) { if ($doc = Document::getByPath($data["link"])) { $tmpLink = $data["link"]; $data["link"] = $doc->getId(); } } $glossary->setValues($data); $glossary->save(); if ($link = $glossary->getLink()) { if (intval($link) > 0) { if ($doc = Document::getById(intval($link))) { $glossary->setLink($doc->getFullPath()); } } } $this->_helper->json(array("data" => $glossary, "success" => true)); } } } } else { Logger::err("user [" . $this->getUser()->getId() . "] attempted to modify static routes, but has no permission to do so."); } } else { // get list of routes $list = new Glossary_List(); $list->setLimit($this->_getParam("limit")); $list->setOffset($this->_getParam("start")); if ($this->_getParam("sort")) { $list->setOrderKey($this->_getParam("sort")); $list->setOrder($this->_getParam("dir")); } if ($this->_getParam("filter")) { $list->setCondition("`text` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%")); } $list->load(); $glossaries = array(); foreach ($list->getGlossary() as $glossary) { if ($link = $glossary->getLink()) { if (intval($link) > 0) { if ($doc = Document::getById(intval($link))) { $glossary->setLink($doc->getFullPath()); } } } $glossaries[] = $glossary; } $this->_helper->json(array("data" => $glossaries, "success" => true, "total" => $list->getTotalCount())); } $this->_helper->json(false); }
/** * Receives a Webservice_Data_Document_Element from webservice import and fill the current tag's data * * @abstract * @param Webservice_Data_Document_Element $data * @return void */ public function getFromWebserviceImport($wsElement) { $data = $wsElement->value; if ($data->id !== null) { $this->type = $data->type; $this->subtype = $data->subtype; $this->id = $data->id; if (is_numeric($this->id)) { if ($this->type == "asset") { $this->element = Asset::getById($this->id); if (!$this->element instanceof Asset) { throw new Exception("cannot get values from web service import - referenced asset with id [ " . $this->id . " ] is unknown"); } } else { if ($this->type == "document") { $this->element = Document::getById($this->id); if (!$this->element instanceof Document) { throw new Exception("cannot get values from web service import - referenced document with id [ " . $this->id . " ] is unknown"); } } else { if ($this->type == "object") { $this->element = Object_Abstract::getById($this->id); if (!$this->element instanceof Object_Abstract) { throw new Exception("cannot get values from web service import - referenced object with id [ " . $this->id . " ] is unknown"); } } else { throw new Exception("cannot get values from web service import - type is not valid"); } } } } else { throw new Exception("cannot get values from web service import - id is not valid"); } } }
/** * @param Webservice_Data_Document $wsDocument * @return bool */ protected function updateDocument($wsDocument) { $document = Document::getById($wsDocument->id); $this->setModificationParams($document, false); if ($document instanceof Document and strtolower($wsDocument->type) == $document->getType()) { $wsDocument->reverseMap($document); $document->save(); return true; } else { if ($document instanceof Document) { throw new Exception("Type mismatch for given document with ID [" . $wsDocument->id . "] and existing document with id [" . $document->getId() . "]"); } else { throw new Exception("Document with given ID (" . $wsDocument->id . ") does not exist."); } } }
<script src="/website/static/js/html5shiv.js"></script> <script src="/website/static/js/respond.min.js"></script> <![endif]--> </head> <body class="<?php echo $isPortal ? "portal-page" : ""; ?> "> <div class="navbar-wrapper"> <?php $mainNavStartNode = $this->document->getProperty("mainNavStartNode"); if (!$mainNavStartNode) { $mainNavStartNode = Document::getById(1); } ?> <div class="container"> <div class="navbar navbar-inverse navbar-static-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="<?php echo $mainNavStartNode; ?> ">
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); }
$el->outertext = ""; } } } if ($el->href) { if (preg_match_all("/(asset|document):([0-9]+)/i", $el->href, $match)) { if ($match[1][0] == "asset") { if ($asset = Asset::getById($match[2][0])) { $el->pimcore_id = $asset->getId(); $el->pimcore_type = "asset"; $el->href = $asset->getFullPath(); } else { $el->outertext = $el->innertext; } } else { if ($match[1][0] == "document") { if ($doc = Document::getById($match[2][0])) { $el->pimcore_id = $doc->getId(); $el->pimcore_type = "document"; $el->href = $doc->getFullPath(); } else { $el->outertext = $el->innertext; } } } } } } $field["data"] = $html->save(); $db->insert("documents_elements", $field); }
public function saveToSessionAction() { if ($this->_getParam("id")) { $key = "document_" . $this->_getParam("id"); $session = new Zend_Session_Namespace("pimcore_documents"); if (!($document = $session->{$key})) { $document = Document::getById($this->_getParam("id")); } // set _fulldump otherwise the properties will be removed because of the session-serialize $document->_fulldump = true; $this->setValuesToDocument($document); $session->{$key} = $document; } $this->removeViewRenderer(); }
/** * Sets the email document * * @param Document_Email $document * @throws Exception */ public function setDocument($document) { if ($document instanceof Document) { //document passed $this->document = $document; } elseif ((int) $document > 0) { //id of document passed $this->setDocument(Document::getById($document)); } elseif (is_string($document) && $document != "") { //path of document passed $this->setDocument(Document::getByPath($document)); } else { throw new Exception('$document is not an instance of Document_Email or at least Document'); } return $this; }
public function __wakeup() { if (isset($this->_fulldump) && $this->properties !== null) { unset($this->_fulldump); $this->renewInheritedProperties(); } if (isset($this->_fulldump)) { // set current key and path this is necessary because the serialized data can have a different path than the original element (element was renamed or moved) $originalElement = Document::getById($this->getId()); if ($originalElement) { $this->setKey($originalElement->getKey()); $this->setPath($originalElement->getPath()); } } }