Exemple #1
0
 /**
  * Moves a file/directory
  *
  * @param string $sourcePath
  * @param string $destinationPath
  * @return void
  */
 public function move($sourcePath, $destinationPath)
 {
     $nameParts = explode("/", $sourcePath);
     $nameParts[count($nameParts) - 1] = Pimcore_File::getValidFilename($nameParts[count($nameParts) - 1]);
     $sourcePath = implode("/", $nameParts);
     $nameParts = explode("/", $destinationPath);
     $nameParts[count($nameParts) - 1] = Pimcore_File::getValidFilename($nameParts[count($nameParts) - 1]);
     $destinationPath = implode("/", $nameParts);
     try {
         if (dirname($sourcePath) == dirname($destinationPath)) {
             try {
                 $destinationNode = $this->getNodeForPath($destinationPath);
                 // If we got here, it means the destination exists, and needs to be overwritten
                 $destinationNode->delete();
             } catch (Sabre_DAV_Exception_FileNotFound $e) {
                 // If we got here, it means the destination node does not yet exist
                 Logger::warning("Sabre_DAV_Exception_FileNotFound");
             }
             $asset = Asset::getByPath("/" . $sourcePath);
             $asset->setFilename(basename($destinationPath));
         } else {
             $asset = Asset::getByPath("/" . $sourcePath);
             $parent = Asset::getByPath("/" . dirname($destinationPath));
             $asset->setPath($parent->getFullPath() . "/");
             $asset->setParentId($parent->getId());
         }
     } catch (Exception $e) {
         Logger::error($e);
     }
     $asset->save();
 }
Exemple #2
0
 /**
  * @static
  * @param Asset_Image|Asset_Video|string
  * @param Asset_Image_Thumbnail_Config $config
  * @param string $path
  * @return string
  */
 public static function process($asset, Asset_Image_Thumbnail_Config $config, $fileSystemPath = null)
 {
     $format = strtolower($config->getFormat());
     if (!$fileSystemPath) {
         $fileSystemPath = $asset->getFileSystemPath();
     }
     // simple detection for source type if SOURCE is selected
     if ($format == "source") {
         $typeMapping = array("gif" => "gif", "jpeg" => "jpeg", "jpg" => "jpeg", "png" => "png");
         $fileExt = Pimcore_File::getFileExtension($asset->getFilename());
         if ($typeMapping[$fileExt]) {
             $format = $typeMapping[$fileExt];
         } else {
             // use PNG if source doesn't have a valid mapping
             $format = "png";
         }
     }
     $filename = "thumb_" . $asset->getId() . "__" . $config->getName() . "." . $format;
     $fsPath = PIMCORE_TEMPORARY_DIRECTORY . "/" . $filename;
     $path = str_replace(PIMCORE_DOCUMENT_ROOT, "", $fsPath);
     // check for existing and still valid thumbnail
     if (is_file($fsPath) and filemtime($fsPath) > $asset->getModificationDate()) {
         return $path;
     }
     // transform image
     $image = Asset_Image::getImageTransformInstance();
     if (!$image->load($fileSystemPath)) {
         return "/pimcore/static/img/image-not-supported.png";
     }
     $transformations = $config->getItems();
     if (is_array($transformations) && count($transformations) > 0) {
         foreach ($transformations as $transformation) {
             if (!empty($transformation)) {
                 $arguments = array();
                 $mapping = self::$argumentMapping[$transformation["method"]];
                 if (is_array($transformation["arguments"])) {
                     foreach ($transformation["arguments"] as $key => $value) {
                         $position = array_search($key, $mapping);
                         if ($position !== false) {
                             $arguments[$position] = $value;
                         }
                     }
                 }
                 ksort($arguments);
                 if (count($mapping) == count($arguments)) {
                     call_user_func_array(array($image, $transformation["method"]), $arguments);
                 } else {
                     $message = "Image Transform failed: cannot call method `" . $transformation["method"] . "´ with arguments `" . implode(",", $arguments) . "´ because there are too few arguments";
                     Logger::error($message);
                 }
             }
         }
     }
     $image->save($fsPath, $format, $config->getQuality());
     return $path;
 }
Exemple #3
0
 /**
  * register a new user
  */
 public function registerAction()
 {
     // init
     $status = array('success' => false, 'message' => 'register failed');
     // check data
     $list = new Object_Customer_List();
     $list->setCondition('email = ?', $this->getParam('email'));
     if ($list->count() === 1) {
         // email already exsits
         $status['message'] = 'Email already exists';
     } else {
         if ($this->getParam('password') != $this->getParam('confirm_password')) {
             // user input errors...
             $status['message'] = 'user input error...';
         } else {
             // create new user
             $user = new Object_Customer();
             $user->setFirstname($this->getParam('firstname'));
             $user->setLastname($this->getParam('lastname'));
             $user->setEmail($this->getParam('email'));
             $user->setPassword($this->getParam('password'));
             // set sys params
             $user->setParentId(10979);
             $user->setKey(Pimcore_File::getValidFilename($this->getParam('email')));
             $user->setPublished(true);
             // done
             $user->save();
             $status['success'] = true;
             $this->loginCustomer($user);
         }
     }
     // send output
     if ($this->getRequest()->isXmlHttpRequest()) {
         $this->_helper->viewRenderer->setNoRender(true);
         $this->getResponse()->setHeader('Content-Type', 'application/json');
         echo Zend_Json::encode($status);
     } else {
         if ($status['success']) {
             $this->redirect('/en/shop');
         } else {
             $this->enableLayout();
             $this->view->status = $status;
         }
     }
 }
 protected function getOrCreateAssetFolderByPath($path)
 {
     $folder = Asset_Folder::getByPath($path);
     if (!$folder instanceof Asset_Folder) {
         str_replace("\\", "/", $path);
         $parts = explode("/", $path);
         if (empty($parts[count($parts) - 1])) {
             $parts = array_slice($parts, 0, -1);
         }
         $parts = array_slice($parts, 1);
         $parentPath = "/";
         foreach ($parts as $part) {
             $parent = Asset_Folder::getByPath($parentPath);
             if ($parent instanceof Asset_Folder) {
                 $part = Pimcore_File::getValidFilename($part);
                 $folder = Asset_Folder::getByPath($parentPath . $part);
                 if (!$folder instanceof Asset_Folder) {
                     $folder = Asset::create($parent->getId(), array("filename" => $part, "type" => "folder", "userOwner" => $this->getUser()->getId(), "userModification" => $this->getUser()->getId()));
                 }
                 $parentPath .= $part . "/";
             } else {
                 Logger::error("parent not found!");
                 return null;
             }
         }
     }
     return $folder;
 }
Exemple #5
0
 /**
  * @param string $name
  * @return string
  */
 function setName($name)
 {
     $this->asset->setFilename(Pimcore_File::getValidFilename($name));
     $this->asset->save();
 }
Exemple #6
0
 /**
  * detects the pimcore internal asset type based on the mime-type and file extension
  *
  * @return void
  */
 public function setTypeFromMapping()
 {
     $found = false;
     $mappings = array("image" => array("/image/", "/\\.eps\$/", "/\\.ai\$/", "/\\.svgz\$/", "/\\.pcx\$/", "/\\.iff\$/", "/\\.pct\$/", "/\\.wmf\$/"), "text" => array("/text/"), "audio" => array("/audio/"), "video" => array("/video/"), "document" => array("/msword/", "/pdf/", "/powerpoint/", "/office/", "/excel/", "/opendocument/"), "archive" => array("/zip/", "/tar/"));
     foreach ($mappings as $type => $patterns) {
         foreach ($patterns as $pattern) {
             if (preg_match($pattern, $this->getMimetype() . " ." . Pimcore_File::getFileExtension($this->getFilename()))) {
                 $this->setType($type);
                 $found = true;
                 break;
             }
         }
         // break at first match
         if ($found) {
             break;
         }
     }
     // default is unknown
     if (!$found) {
         $this->setType("unknown");
     }
 }
Exemple #7
0
 /**
  * Returns a uniqe key for the element in the $target-Path (recursive)
  * @static
  * @return Element_Interface|string
  * @param string $type
  * @param string $sourceKey
  * @param Element_Interface $target
  */
 public static function getSaveCopyName($type, $sourceKey, $target)
 {
     $equalElement = self::getElementByPath($type, $target->getFullPath() . "/" . $sourceKey);
     if ($equalElement) {
         // only for assets: add the prefix _copy before the file extension (if exist) not after to that source.jpg will be source_copy.jpg and not source.jpg_copy
         if ($type == "asset" && ($fileExtension = Pimcore_File::getFileExtension($sourceKey))) {
             $sourceKey = str_replace("." . $fileExtension, "_copy." . $fileExtension, $sourceKey);
         } else {
             $sourceKey .= "_copy";
         }
         return self::getSaveCopyName($type, $sourceKey, $target);
     }
     return $sourceKey;
 }
Exemple #8
0
/**
 * @depricated
 * @param  $filename
 * @return bool
 */
function is_includeable($filename)
{
    return Pimcore_File::isIncludeable($filename);
}
 public function importProcessAction()
 {
     $success = true;
     $type = $this->_getParam("type");
     $parentId = $this->_getParam("parentId");
     $job = $this->_getParam("job");
     $id = $this->_getParam("id");
     $mappingRaw = Zend_Json::decode($this->_getParam("mapping"));
     $class = Object_Class::getById($this->_getParam("classId"));
     $skipFirstRow = $this->_getParam("skipHeadRow") == "true";
     $fields = $class->getFieldDefinitions();
     $file = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_" . $id;
     if ($type == "csv") {
         // determine type
         $dialect = Pimcore_Tool_Admin::determineCsvDialect(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_" . $id . "_original");
         $count = 0;
         if (($handle = fopen($file, "r")) !== false) {
             $data = fgetcsv($handle, 1000, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar);
         }
         if ($skipFirstRow && $job == 1) {
             //read the next row, we need to skip the head row
             $data = fgetcsv($handle, 1000, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar);
         }
         $tmpFile = $file . "_tmp";
         $tmpHandle = fopen($tmpFile, "w+");
         while (!feof($handle)) {
             $buffer = fgets($handle);
             fwrite($tmpHandle, $buffer);
         }
         fclose($handle);
         fclose($tmpHandle);
         unlink($file);
         rename($tmpFile, $file);
     }
     // prepare mapping
     foreach ($mappingRaw as $map) {
         if ($map[0] !== "" && $map[1] && !empty($map[2])) {
             $mapping[$map[2]] = $map[0];
         } else {
             if ($map[1] == "published (system)") {
                 $mapping["published"] = $map[0];
             }
         }
     }
     // create new object
     $className = "Object_" . ucfirst($this->_getParam("className"));
     $parent = Object_Abstract::getById($this->_getParam("parentId"));
     $parent->getPermissionsForUser($this->getUser());
     $objectKey = "object_" . $job;
     if ($this->_getParam("filename") == "id") {
         $objectKey = null;
     } else {
         if ($this->_getParam("filename") != "default") {
             $objectKey = Pimcore_File::getValidFilename($data[$this->_getParam("filename")]);
         }
     }
     $overwrite = false;
     if ($this->_getParam("overwrite") == "true") {
         $overwrite = true;
     }
     if ($parent->isAllowed("create")) {
         $intendedPath = $parent->getFullPath() . "/" . $objectKey;
         if ($overwrite) {
             $object = Object_Abstract::getByPath($intendedPath);
             if (!$object instanceof Object_Concrete) {
                 //create new object
                 $object = new $className();
             } else {
                 if (object instanceof Object_Concrete and $object->getO_className() !== $className) {
                     //delete the old object it is of a different class
                     $object->delete();
                     $object = new $className();
                 } else {
                     if (object instanceof Object_Folder) {
                         //delete the folder
                         $object->delete();
                         $object = new $className();
                     } else {
                         //use the existing object
                     }
                 }
             }
         } else {
             $counter = 1;
             while (Object_Abstract::getByPath($intendedPath) != null) {
                 $objectKey .= "_" . $counter;
                 $intendedPath = $parent->getFullPath() . "/" . $objectKey;
                 $counter++;
             }
             $object = new $className();
         }
         $object->setClassId($this->_getParam("classId"));
         $object->setClassName($this->_getParam("className"));
         $object->setParentId($this->_getParam("parentId"));
         $object->setKey($objectKey);
         $object->setCreationDate(time());
         $object->setUserOwner($this->getUser()->getId());
         $object->setUserModification($this->getUser()->getId());
         if ($data[$mapping["published"]] === "1") {
             $object->setPublished(true);
         } else {
             $object->setPublished(false);
         }
         foreach ($class->getFieldDefinitions() as $key => $field) {
             $value = $data[$mapping[$key]];
             if (array_key_exists($key, $mapping) and $value != null) {
                 // data mapping
                 $value = $field->getFromCsvImport($value);
                 if ($value !== null) {
                     $object->setValue($key, $value);
                 }
             }
         }
         try {
             $object->save();
             $this->_helper->json(array("success" => true));
         } catch (Exception $e) {
             $this->_helper->json(array("success" => false, "message" => $object->getKey() . " - " . $e->getMessage()));
         }
     }
     $this->_helper->json(array("success" => $success));
 }
 protected function determineResourceClass($className)
 {
     $fileToInclude = str_replace("_", "/", $className) . ".php";
     if (Pimcore_File::isIncludeable($fileToInclude)) {
         include_once $fileToInclude;
         if (Pimcore_Tool::classExists($className)) {
             return $className;
         }
     } else {
         Logger::debug("Couldn't find resource implementation " . $className . " for " . get_class($this));
     }
     return;
 }
Exemple #11
0
 /**
  * @throws Exception
  * @param $method
  * @param $arguments
  * @return mixed|string|Tag
  */
 public function __call($method, $arguments)
 {
     $class = "Document_Tag_" . ucfirst(strtolower($method));
     $tagFile = str_replace("_", "/", $class) . ".php";
     if (Pimcore_File::isIncludeable($tagFile)) {
         include_once $tagFile;
         if (@Pimcore_Tool::classExists($class)) {
             if (!isset($arguments[0])) {
                 throw new Exception("You have to set a name for the called tag (editable): " . $method);
             }
             // set default if there is no editable configuration provided
             if (!isset($arguments[1])) {
                 $arguments[1] = array();
             }
             return $this->tag($method, $arguments[0], $arguments[1]);
         }
     }
     if ($this->document instanceof Document) {
         if (method_exists($this->document, $method)) {
             return call_user_func_array(array($this->document, $method), $arguments);
         }
     }
     return parent::__call($method, $arguments);
 }
 public function getValidFilenameAction()
 {
     $this->_helper->json(array("filename" => Pimcore_File::getValidFilename($this->_getParam("value"))));
 }