Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * @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;
 }
Example #3
0
 /**
  * Get the assets from database
  *
  * @return array
  */
 public function load()
 {
     $assets = array();
     $assetsData = $this->db->fetchAll("SELECT id,type FROM assets" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($assetsData as $assetData) {
         if ($assetData["type"]) {
             $assets[] = Asset::getById($assetData["id"]);
         }
     }
     $this->model->setAssets($assets);
     return $assets;
 }
Example #4
0
 /**
  * legacy - not required anymore
  *
  *
  * @return void
  */
 protected function cleanUp()
 {
     try {
         $class = Object_Class::getByName("unittest");
         if ($class instanceof Object_Class) {
             $class->delete();
         }
     } catch (Exception $e) {
     }
     try {
         $objectRoot = Object_Abstract::getById(1);
         if ($objectRoot and $objectRoot->hasChilds()) {
             $childs = $objectRoot->getChilds();
             foreach ($childs as $child) {
                 $child->delete();
             }
         }
     } catch (Exception $e) {
     }
     try {
         $assetRoot = Asset::getById(1);
         if ($assetRoot and $assetRoot->hasChilds()) {
             $childs = $assetRoot->getChilds();
             foreach ($childs as $child) {
                 $child->delete();
             }
         }
     } catch (Exception $e) {
     }
     try {
         $documentRoot = Asset::getById(1);
         if ($documentRoot and $documentRoot->hasChilds()) {
             $childs = $documentRoot->getChilds();
             foreach ($childs as $child) {
                 $child->delete();
             }
         }
     } catch (Exception $e) {
     }
     try {
         $userList = new User_List();
         $userList->setCondition("id > 1");
         $users = $userList->load();
         if (is_array($users) and count($users) > 0) {
             foreach ($users as $user) {
                 $user->delete();
             }
         }
     } catch (Exception $e) {
     }
 }
Example #5
0
 /**
  * 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);
 }
Example #6
0
 /**
  * @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");
     }
 }
Example #7
0
 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();
 }
Example #8
0
 /**
  *
  */
 public function maintenanceCleanUp()
 {
     $conf["document"] = Pimcore_Config::getSystemConfig()->documents->versions;
     $conf["asset"] = Pimcore_Config::getSystemConfig()->assets->versions;
     $conf["object"] = Pimcore_Config::getSystemConfig()->objects->versions;
     $elementTypes = array();
     foreach ($conf as $elementType => $tConf) {
         if (intval($tConf->days) > 0) {
             $versioningType = "days";
             $value = intval($tConf->days);
         } else {
             $versioningType = "steps";
             $value = intval($tConf->steps);
         }
         if ($versioningType) {
             $elementTypes[] = array("elementType" => $elementType, $versioningType => $value);
         }
     }
     $versions = $this->getResource()->maintenanceGetOutdatedVersions($elementTypes);
     if (is_array($versions)) {
         foreach ($versions as $index => $id) {
             $version = Version::getById($id);
             if ($version->getCtype() == "document") {
                 $element = Document::getById($version->getCid());
             } else {
                 if ($version->getCtype() == "asset") {
                     $element = Asset::getById($version->getCid());
                 } else {
                     if ($version->getCtype() == "object") {
                         $element = Object_Abstract::getById($version->getCid());
                     }
                 }
             }
             if ($element instanceof Element_Interface) {
                 if ($element->getModificationDate() > $version->getDate()) {
                     // delete version if it is outdated
                     $version->delete();
                 }
             } else {
                 // delete version if the correspondening element doesn't exist anymore
                 $version->delete();
             }
             // call the garbage collector every 100 iterations, to avoid a out-of-memory
             if ($index % 100 == 0) {
                 Pimcore::collectGarbage();
             }
         }
     }
 }
 foreach ($s as $el) {
     if ($el->src) {
         if (preg_match("/asset:([0-9]+)/i", $el->src, $match)) {
             if ($asset = Asset::getById($match[1])) {
                 $el->pimcore_id = $asset->getId();
                 $el->pimcore_type = "asset";
                 $el->src = $asset->getFullPath();
             } else {
                 $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;
                     }
Example #10
0
 /**
  * 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;
 }
Example #11
0
 /**
  * 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");
 }
Example #12
0
 /**
  * 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");
         }
     }
 }
Example #13
0
 /**
  * @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;
 }
Example #14
0
 /**
  * @param Webservice_Data_Asset $wsDocument
  * @return bool
  */
 protected function updateAsset($wsDocument)
 {
     $asset = Asset::getById($wsDocument->id);
     $this->setModificationParams($asset, false);
     if ($asset instanceof Asset and $asset->getType() == strtolower($wsDocument->type)) {
         $wsDocument->reverseMap($asset);
         $asset->save();
         return true;
     } else {
         if ($asset instanceof Asset) {
             throw new Exception("Type mismatch for given asset with ID [" . $wsDocument->id . "] and existing asset with id [" . $asset->getId() . "]");
         } else {
             throw new Exception("Asset with given ID (" . $wsDocument->id . ") does not exist.");
         }
     }
 }
Example #15
0
 public function readGoogleResponse($googleResponse)
 {
     $this->setRaw($googleResponse);
     $this->setTotal(intval($googleResponse["searchInformation"]["totalResults"]));
     $items = array();
     if (array_key_exists("items", $googleResponse) && is_array($googleResponse["items"])) {
         foreach ($googleResponse["items"] as $item) {
             // check for relation to document or asset
             // first check for an image
             if (array_key_exists("pagemap", $item) && is_array($item["pagemap"])) {
                 if (array_key_exists("cse_image", $item["pagemap"]) && is_array($item["pagemap"]["cse_image"])) {
                     if ($item["pagemap"]["cse_image"][0]) {
                         // try to get the asset id
                         if (preg_match("/thumb_([0-9]+)__/", $item["pagemap"]["cse_image"][0]["src"], $matches)) {
                             $test = $matches;
                             if ($matches[1]) {
                                 if ($image = Asset::getById($matches[1])) {
                                     if ($image instanceof Asset_Image) {
                                         $item["image"] = $image;
                                     }
                                 }
                             }
                         }
                         if (!array_key_exists("image", $item)) {
                             $item["image"] = $item["pagemap"]["cse_image"][0]["src"];
                         }
                     }
                 }
             }
             // now a document
             $urlParts = parse_url($item["link"]);
             if ($document = Document::getByPath($urlParts["path"])) {
                 $item["document"] = $document;
             }
             $items[] = new Pimcore_Google_Cse_Item($item);
         }
     }
     $this->setResults($items);
 }
Example #16
0
 public static function execute($processId)
 {
     $instance = new self();
     $instance->setProcessId($processId);
     $instance = Pimcore_Tool_Serialize::unserialize(file_get_contents($instance->getJobFile()));
     $formats = array();
     $overallStatus = array();
     // set overall status for all formats to 0
     foreach ($instance->queue as $converter) {
         $overallStatus[$converter->getFormat()] = 0;
     }
     // check if there is already a transcoding process running, wait if so ...
     while ($instance->isLocked()) {
         sleep(10);
     }
     $instance->lock();
     // start converting
     foreach ($instance->queue as $converter) {
         try {
             Logger::info("start video " . $converter->getFormat() . " to " . $converter->getDestinationFile());
             $converter->save();
             while (!$converter->isFinished()) {
                 sleep(5);
                 $overallStatus[$converter->getFormat()] = $converter->getConversionStatus();
                 $a = 0;
                 foreach ($overallStatus as $f => $s) {
                     $a += $s;
                 }
                 $a = $a / count($overallStatus);
                 $instance->setStatus($a);
                 $instance->save();
             }
             Logger::info("finished video " . $converter->getFormat() . " to " . $converter->getDestinationFile());
             if ($converter->getConversionStatus() !== "error") {
                 $formats[$converter->getFormat()] = str_replace(PIMCORE_DOCUMENT_ROOT, "", $converter->getDestinationFile());
             }
             $converter->destroy();
         } catch (Exception $e) {
             Logger::error($e);
         }
     }
     $instance->unlock();
     $asset = Asset::getById($instance->getAssetId());
     if ($asset) {
         $customSetting = $asset->getCustomSetting("thumbnails");
         $customSetting = is_array($customSetting) ? $customSetting : array();
         if (array_key_exists($instance->getConfig()->getName(), $customSetting) && array_key_exists("formats", $customSetting[$instance->getConfig()->getName()]) && is_array($customSetting[$instance->getConfig()->getName()]["formats"])) {
             $formats = array_merge($customSetting[$instance->getConfig()->getName()]["formats"], $formats);
         }
         $customSetting[$instance->getConfig()->getName()] = array("status" => "finished", "formats" => $formats);
         $asset->setCustomSetting("thumbnails", $customSetting);
         $asset->save();
     }
     @unlink($instance->getJobFile());
 }
Example #17
0
 /**
  * @param $thumbnailName
  */
 public function getImageThumbnail($thumbnailName, $timeOffset = null, $imageAsset = null)
 {
     $cs = $this->getCustomSetting("image_thumbnail_time");
     $im = $this->getCustomSetting("image_thumbnail_asset");
     if (!$timeOffset && !$imageAsset && $cs) {
         $timeOffset = $cs;
     } else {
         if (!$timeOffset && !$imageAsset && $im) {
             $imageAsset = Asset::getById($im);
         }
     }
     // fallback
     if (!$timeOffset && !$imageAsset) {
         $timeOffset = 5;
     }
     if ($imageAsset instanceof Asset_Image) {
         return $imageAsset->getThumbnail($thumbnailName);
     }
     $thumbnail = $this->getImageThumbnailConfig($thumbnailName);
     $thumbnail->setName($thumbnail->getName() . "-" . $timeOffset);
     $converter = Pimcore_Video::getInstance();
     $converter->load($this->getFileSystemPath());
     $path = PIMCORE_TEMPORARY_DIRECTORY . "/video_" . $this->getId() . "__thumbnail_" . $timeOffset . ".png";
     if (!is_file($path)) {
         $converter->saveImage($path, $timeOffset);
     }
     if ($thumbnail) {
         try {
             $path = Asset_Image_Thumbnail_Processor::process($this, $thumbnail, $path);
         } catch (Exception $e) {
             Logger::error("Couldn't create image-thumbnail of video " . $this->getFullPath());
             Logger::error($e);
             return "/pimcore/static/img/filetype-not-supported.png";
         }
     }
     // if no thumbnail config is given return the original image
     if (empty($path)) {
         $fsPath = $this->getFileSystemPath();
         $path = str_replace(PIMCORE_DOCUMENT_ROOT, "", $fsPath);
         return $path;
     }
     return $path;
 }
Example #18
0
 public function importAction()
 {
     $importService = new Element_Import_Service($this->getUser());
     $this->removeViewRenderer();
     $parentId = $this->_getParam("parentId");
     $type = $this->_getParam("type");
     $overwrite = $this->_getParam("overwrite");
     if ($type == "document") {
         $rootElement = Document::getById($parentId);
     } else {
         if ($type == "object") {
             $rootElement = Object_Abstract::getById($parentId);
         } else {
             if ($type == "asset") {
                 $rootElement = Asset::getById($parentId);
             }
         }
     }
     if (!$rootElement) {
         throw new Exception("Invalid root element for import");
     }
     $exportName = "export_" . Zend_Session::getId();
     $exportDir = PIMCORE_TEMPORARY_DIRECTORY . "/" . $exportName;
     $exportArchive = $exportDir . ".zip";
     $tmpDirectory = PIMCORE_TEMPORARY_DIRECTORY . "/element_import_" . Zend_Session::getId();
     if (is_dir($tmpDirectory)) {
         recursiveDelete($tmpDirectory);
     }
     $zip = new ZipArchive();
     if ($zip->open($exportArchive) === TRUE) {
         $zip->extractTo($tmpDirectory);
         $zip->close();
     }
     $importService->doImport($tmpDirectory, $rootElement, $overwrite);
     p_r($importService->getImportInfo());
     // cleanup
     recursiveDelete($tmpDirectory);
 }
Example #19
0
 /**
  * converts data to be imported via webservices
  * @param mixed $value
  * @return mixed
  */
 public function getFromWebserviceImport($value)
 {
     $asset = Asset::getById($value);
     if (empty($value)) {
         return null;
     } else {
         if (is_numeric($value) and $asset instanceof Asset) {
             return $asset;
         } else {
             throw new Exception("cannot get values from web service import - invalid data, referencing unknown asset with id [ " . $value . " ]");
         }
     }
 }
Example #20
0
 public function getDefaultImage()
 {
     $defaultImage = \Asset::getById(73);
     return $defaultImage;
 }
Example #21
0
<?php

$this->template("/includes/content-headline.php");
?>


<?php 
echo $this->areablock("content");
?>

<?php 
// this is just used for demonstration
$image = Asset::getById(53);
?>

<h2>
    <?php 
echo $this->translate("Original Dimensions of the Image");
?>
:
    <?php 
echo $image->getWidth() . "x" . $image->getHeight();
?>
</h2>

<section class="thumbnail-examples">
    <?php 
$thumbnails = ["Cover" => "exampleCover", "Contain" => "exampleContain", "Frame" => "exampleFrame", "Rotate" => "exampleRotate", "Resize" => "exampleResize", "Scale by Width" => "exampleScaleWidth", "Scale by Height" => "exampleScaleHeight", "Contain &amp; Overlay" => "exampleOverlay", "Rounded Corners" => "exampleCorners", "Sepia" => "exampleSepia", "Grayscale" => "exampleGrayscale", "Mask" => "exampleMask", "Combined 1" => "exampleCombined1", "Combined 2" => "exampleCombined2"];
?>

    <?php 
Example #22
0
 /**
  * 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) {
         if ($data->type == "asset") {
             $this->id = $data->id;
             $asset = Asset::getById($data->id);
             if (!$asset) {
                 throw new Exception("Referencing unknown asset with id [ " . $data->id . " ] in webservice import field [ " . $data->name . " ]");
             }
             $this->type = $data->type;
         } else {
             if (in_array($data->type, array("vimeo", "youtube", "url"))) {
                 $this->id = $data->id;
                 $this->type = $data->type;
             } else {
                 throw new Exception("cannot get values from web service import - type must be asset,youtube,url or vimeo ");
             }
         }
     }
 }
Example #23
0
 /**
  * @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();
     }
 }
Example #24
0
 /**
  * @see Object_Class_Data::getDataFromEditmode
  * @param array $data
  * @param null|Object_Abstract $object
  * @return array
  */
 public function getDataFromEditmode($data, $object = null)
 {
     //if not set, return null
     if ($data === null or $data === FALSE) {
         return null;
     }
     $elements = array();
     if (is_array($data) && count($data) > 0) {
         foreach ($data as $element) {
             if ($element["type"] == "object") {
                 $e = Object_Abstract::getById($element["id"]);
             } else {
                 if ($element["type"] == "asset") {
                     $e = Asset::getById($element["id"]);
                 } else {
                     if ($element["type"] == "document") {
                         $e = Document::getById($element["id"]);
                     }
                 }
             }
             if ($e instanceof Element_Interface) {
                 $elements[] = $e;
             }
         }
     }
     //must return array if data shall be set
     return $elements;
 }
Example #25
0
 /**
  * @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;
 }
Example #26
0
 /**
  * @param mixed $data
  * @param Object_Concrete $ownerObject
  * @param array $blockedTags
  */
 public function getCacheTags($data, $ownerObject, $tags = array())
 {
     $tags = is_array($tags) ? $tags : array();
     if ($data instanceof Object_Data_Link and $data->getInternal()) {
         if (intval($data->getInternal()) > 0) {
             if ($data->getInternalType() == "document") {
                 if ($doc = Document::getById($data->getInternal())) {
                     if (!array_key_exists($doc->getCacheTag(), $tags)) {
                         $tags = $doc->getCacheTags($tags);
                     }
                 }
             } else {
                 if ($data->getInternalType() == "asset") {
                     if ($asset = Asset::getById($data->getInternal())) {
                         if (!array_key_exists($asset->getCacheTag(), $tags)) {
                             $tags = $asset->getCacheTags($tags);
                         }
                     }
                 }
             }
         }
     }
     return $tags;
 }
Example #27
0
 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 = Asset::getById($this->getId());
         if ($originalElement) {
             $this->setFilename($originalElement->getFilename());
             $this->setPath($originalElement->getPath());
         }
     }
 }
Example #28
0
 /**
  * @param  $fd
  * @return void
  */
 protected function setFieldData($object, $fd, $refDocument, $refAsset, $minAmountLazyRelations)
 {
     foreach ($fd as $field) {
         $name = $field->getName();
         $type = $field->getFieldType();
         $class = "Object_Class_Data_" . ucfirst($type);
         $this->assertTrue(class_exists($class));
         $data = new $class();
         $setter = "set" . ucfirst($name);
         if (!$field->isRelationType() or !$field->isRemoteOwner()) {
             $this->assertTrue(method_exists($object, $setter));
         }
         if ($data instanceof Object_Class_Data_Checkbox) {
             $object->{$setter}(true);
         } else {
             if ($data instanceof Object_Class_Data_Time) {
                 $object->{$setter}("18:00");
             } else {
                 if ($data instanceof Object_Class_Data_Password) {
                     $object->{$setter}("verySecret");
                 } else {
                     if ($data instanceof Object_Class_Data_Input) {
                         $object->{$setter}("simple input");
                     } else {
                         if ($data instanceof Object_Class_Data_Date) {
                             $object->{$setter}(new Zend_Date());
                         } else {
                             if ($data instanceof Object_Class_Data_Datetime) {
                                 $object->{$setter}(new Zend_Date());
                             } else {
                                 if ($data instanceof Object_Class_Data_Href) {
                                     $object->{$setter}(Object_Abstract::getById($object->getId() - 1));
                                 } else {
                                     if ($data instanceof Object_Class_Data_Objects and !$data->isRemoteOwner()) {
                                         $data = array();
                                         $o = Object_Abstract::getById($object->getId() - 1);
                                         if (!$o instanceof Object_Folder) {
                                             $data[] = $o;
                                         }
                                         $data[] = Object_Abstract::getById($object->getId());
                                         $object->{$setter}($data);
                                     } else {
                                         if ($data instanceof Object_Class_Data_Fieldcollections) {
                                             $items = new Object_Fieldcollection();
                                             $collectionA = Object_Fieldcollection_Definition::getByKey("collectionA");
                                             $itemDefinitions = $collectionA->getFieldDefinitions();
                                             $item = new Object_Fieldcollection_Data_CollectionA();
                                             $this->setFieldData($item, $itemDefinitions, $refDocument, $refAsset, $minAmountLazyRelations);
                                             $items->add($item);
                                             $object->{$setter}($items);
                                         } else {
                                             if ($data instanceof Object_Class_Data_Localizedfields) {
                                                 $getter = "get" . ucfirst($name);
                                                 $data = $object->getO_class()->getFieldDefinition("localizedfields");
                                                 $localizedData = array();
                                                 $validLanguages = Pimcore_Tool::getValidLanguages();
                                                 foreach ($validLanguages as $language) {
                                                     foreach ($data->getFieldDefinitions() as $fd) {
                                                         $fieldData = $this->getLocalizedFieldDataFor($fd, $language, $refAsset);
                                                         $localizedData[$language][$fd->getName()] = $fieldData;
                                                     }
                                                 }
                                                 $object->{$setter}(new Object_Localizedfield($localizedData));
                                             } else {
                                                 if ($data instanceof Object_Class_Data_Multihref) {
                                                     $data = array();
                                                     $data[] = Object_Abstract::getById($object->getId() - 1);
                                                     $data[] = $refAsset;
                                                     //dummy for checking if relation is saved twice
                                                     $data[] = Asset::getById($refAsset->getId());
                                                     $data[] = $refDocument;
                                                     $fd = $object->geto_Class()->getFieldDefinition($name);
                                                     if ($fd->getLazyLoading()) {
                                                         for ($i = 1; $i <= $minAmountLazyRelations; $i++) {
                                                             $data[] = $this->createRandomObject("unittest");
                                                         }
                                                     }
                                                     $object->{$setter}($data);
                                                 } else {
                                                     if ($data instanceof Object_Class_Data_Languagemultiselect) {
                                                         $object->{$setter}(array("de", "en"));
                                                     } else {
                                                         if ($data instanceof Object_Class_Data_Countrymultiselect) {
                                                             $object->{$setter}(array("AT", "AU"));
                                                         } else {
                                                             if ($data instanceof Object_Class_Data_Multiselect) {
                                                                 $object->{$setter}(array("cat", "cow"));
                                                             } else {
                                                                 if ($data instanceof Object_Class_Data_User) {
                                                                     //create a user to set
                                                                     $user = new User();
                                                                     $user->setUsername(uniqid());
                                                                     $user->setParentId(0);
                                                                     $user->setHasCredentials(true);
                                                                     $user->setPassword(md5("unitTestUser"));
                                                                     $user->save();
                                                                     $object->{$setter}($user->getId());
                                                                 } else {
                                                                     if ($data instanceof Object_Class_Data_Language) {
                                                                         $object->{$setter}("en");
                                                                     } else {
                                                                         if ($data instanceof Object_Class_Data_Country) {
                                                                             $object->{$setter}("AU");
                                                                         } else {
                                                                             if ($data instanceof Object_Class_Data_Select) {
                                                                                 $object->{$setter}(2);
                                                                             } else {
                                                                                 if ($data instanceof Object_Class_Data_Geobounds) {
                                                                                     $object->{$setter}(new Object_Data_Geobounds(new Object_Data_Geopoint(150.96588134765625, -33.704920213014425), new Object_Data_Geopoint(150.60333251953125, -33.893217379440884)));
                                                                                 } else {
                                                                                     if ($data instanceof Object_Class_Data_Geopoint) {
                                                                                         $object->{$setter}(new Object_Data_Geopoint(151.2111111, -33.8599722));
                                                                                     } else {
                                                                                         if ($data instanceof Object_Class_Data_Geopolygon) {
                                                                                             $data = array(new Object_Data_Geopoint(150.54428100585938, -33.464671118242684), new Object_Data_Geopoint(150.73654174804688, -33.913733814316245), new Object_Data_Geopoint(151.2542724609375, -33.9946115848146));
                                                                                             $object->{$setter}($data);
                                                                                         } else {
                                                                                             if ($data instanceof Object_Class_Data_Image) {
                                                                                                 $object->{$setter}($refAsset);
                                                                                             } else {
                                                                                                 if ($data instanceof Object_Class_Data_Slider) {
                                                                                                     $object->{$setter}(6);
                                                                                                 } else {
                                                                                                     if ($data instanceof Object_Class_Data_Numeric) {
                                                                                                         $object->{$setter}(12000);
                                                                                                     } else {
                                                                                                         if ($data instanceof Object_Class_Data_Table) {
                                                                                                             $object->{$setter}(array(array("eins", "zwei", "drei"), array(1, 2, 3), array("a", "b", "c")));
                                                                                                         } else {
                                                                                                             if ($data instanceof Object_Class_Data_Textarea) {
                                                                                                                 $object->{$setter}("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.");
                                                                                                             } else {
                                                                                                                 if ($data instanceof Object_Class_Data_Wysiwyg) {
                                                                                                                     $object->{$setter}("<p>This is some <strong>HTML</strong> content</p><ul><li>list one</li><li>list two</li></ul>");
                                                                                                                 } else {
                                                                                                                     if ($data instanceof Object_Class_Data_Link) {
                                                                                                                         $l = new Object_Data_Link();
                                                                                                                         $l->setPath("http://www.pimcore.org");
                                                                                                                         $l->setTitle("pimcore.org");
                                                                                                                         $l->setText("pimcore.org");
                                                                                                                         $object->{$setter}($l);
                                                                                                                     }
                                                                                                                 }
                                                                                                             }
                                                                                                         }
                                                                                                     }
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 protected function importFromFileSystem($path, $parentId)
 {
     $assetFolder = Asset::getById($parentId);
     $files = rscandir($path . "/");
     foreach ($files as $file) {
         if (is_file($file)) {
             $relativePath = $assetFolder->getFullPath() . str_replace($path, "", $file);
             $folder = $this->getOrCreateAssetFolderByPath(dirname($relativePath));
             $filename = basename($file);
             // check for dublicate filename
             $filename = Pimcore_File::getValidFilename($filename);
             $filename = $this->getSafeFilename($folder->getFullPath(), $filename);
             if ($assetFolder->isAllowed("create")) {
                 $asset = Asset::create($folder->getId(), array("filename" => $filename, "data" => file_get_contents($file), "userOwner" => $this->getUser()->getId(), "userModification" => $this->getUser()->getId()));
             } else {
                 Logger::debug("prevented creating asset because of missing permissions ");
             }
         }
     }
 }
Example #30
0
 public function svgAction()
 {
     $asset = Asset::getById(4874);
     $asset->clearThumbnails(true);
     $thumb = $asset->getThumbnail(array("width" => 1800));
     header("Content-Type: image/png");
     while (@ob_end_flush()) {
     }
     flush();
     readfile($thumb->getFileSystemPath());
     exit;
 }