Ejemplo n.º 1
0
 /**
  * @static
  * @return array
  */
 public static function createClassMappings()
 {
     $modelsDir = PIMCORE_PATH . "/models/";
     $files = rscandir($modelsDir);
     $includePatterns = array("/Webservice\\/Data/");
     foreach ($files as $file) {
         if (is_file($file)) {
             $file = str_replace($modelsDir, "", $file);
             $file = str_replace(".php", "", $file);
             $class = str_replace(DIRECTORY_SEPARATOR, "_", $file);
             if (Pimcore_Tool::classExists($class)) {
                 $match = false;
                 foreach ($includePatterns as $pattern) {
                     if (preg_match($pattern, $file)) {
                         $match = true;
                         break;
                     }
                 }
                 if (strpos($file, "Webservice" . DIRECTORY_SEPARATOR . "Data") !== false) {
                     $match = true;
                 }
                 if (!$match) {
                     continue;
                 }
                 $classMap[str_replace("Webservice_Data_", "", $class)] = $class;
             }
         }
     }
     return $classMap;
 }
Ejemplo n.º 2
0
 public static function generateLayoutTreeFromArray($array)
 {
     if (is_array($array) && count($array) > 0) {
         $class = "Object_Class_" . ucfirst($array["datatype"]) . "_" . ucfirst($array["fieldtype"]);
         if (Pimcore_Tool::classExists($class)) {
             $item = new $class();
             if (method_exists($item, "addChild")) {
                 // allows childs
                 $item->setValues($array, array("childs"));
                 if ($array["childs"]["datatype"]) {
                     $childO = self::generateLayoutTreeFromArray($array["childs"]);
                     $item->addChild($childO);
                 } else {
                     if (is_array($array["childs"]) && count($array["childs"]) > 0) {
                         foreach ($array["childs"] as $child) {
                             $childO = self::generateLayoutTreeFromArray($child);
                             $item->addChild($childO);
                         }
                     }
                 }
             } else {
                 $item->setValues($array);
             }
             return $item;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * @static
  * @param Element_Interface $object
  * @param string $type  "in" or "out"
  * @param  string $class
  * @return array
  */
 public static function map($object, $apiclass, $type)
 {
     if ($object instanceof Zend_Date) {
         $object = $object->toString();
     } else {
         if (is_object($object)) {
             if (Pimcore_Tool::classExists($apiclass)) {
                 $new = new $apiclass();
                 if (method_exists($new, "map")) {
                     $new->map($object);
                     $object = $new;
                 }
             } else {
                 throw new Exception("Webservice_Data_Mapper: Cannot map [ {$apiclass} ] - class does not exist");
             }
         } else {
             if (is_array($object)) {
                 $tmpArray = array();
                 foreach ($object as $v) {
                     $className = self::findWebserviceClass($v, $type);
                     $tmpArray[] = self::map($v, $className, $type);
                 }
                 $object = $tmpArray;
             }
         }
     }
     return $object;
 }
Ejemplo n.º 4
0
 /**
  * @param string $module
  * @return void
  */
 public function registerModule($module)
 {
     if (Pimcore_Tool::classExists($module)) {
         $this->_systemModules[] = new $module();
     } else {
         throw new Exception("unknown module [ {$module} ].");
     }
 }
Ejemplo n.º 5
0
 /**
  * @static
  * @return null|Pimcore_Video_Adapter
  */
 public static function getInstance($adapter = null)
 {
     try {
         if ($adapter) {
             $adapterClass = "Pimcore_Video_Adapter_" . $adapter;
             if (Pimcore_Tool::classExists($adapterClass)) {
                 return new $adapterClass();
             } else {
                 throw new Exception("Video-transcode adapter `" . $adapter . "´ does not exist.");
             }
         } else {
             return new Pimcore_Video_Adapter_Ffmpeg();
         }
     } catch (Exception $e) {
         Logger::crit("Unable to load video adapter: " . $e->getMessage());
         throw $e;
     }
     return null;
 }
Ejemplo n.º 6
0
 /**
  * @static
  * @return null|Pimcore_Image_Adapter
  */
 public static function getInstance($adapter = null)
 {
     try {
         if ($adapter) {
             $adapterClass = "Pimcore_Image_Adapter_" . $adapter;
             if (Pimcore_Tool::classExists($adapterClass)) {
                 return new $adapterClass();
             } else {
                 throw new Exception("Image-transform adapter `" . $adapter . "´ does not exist.");
             }
         } else {
             if (extension_loaded("imagick")) {
                 return new Pimcore_Image_Adapter_Imagick();
             } else {
                 return new Pimcore_Image_Adapter_GD();
             }
         }
     } catch (Exception $e) {
         Logger::crit("Unable to load image extensions: " . $e->getMessage());
         throw $e;
     }
     return null;
 }
Ejemplo n.º 7
0
 public function reverseMap($object, $disableMappingExceptions = false)
 {
     $keys = get_object_vars($this);
     foreach ($keys as $key => $value) {
         $method = "setO_" . $key;
         if (method_exists($object, $method)) {
             $object->{$method}($value);
         }
     }
     //must be after generic setters above!!
     parent::reverseMap($object, $disableMappingExceptions);
     if (is_array($this->elements)) {
         foreach ($this->elements as $element) {
             $class = "Object_Class_Data_" . ucfirst($element->type);
             if (Pimcore_Tool::classExists($class)) {
                 $setter = "set" . ucfirst($element->name);
                 if (method_exists($object, $setter)) {
                     $tag = $object->getO_class()->getFieldDefinition($element->name);
                     if ($class instanceof Object_Class_Data_Fieldcollections) {
                         $object->{$setter}($tag->getFromWebserviceImport($element->fieldcollection));
                     } else {
                         $object->{$setter}($tag->getFromWebserviceImport($element->value, $object));
                     }
                 } else {
                     if (!$disableMappingExceptions) {
                         throw new Exception("Unable to reverse map element [ " . $element->name . " ] of type [ " . $element->type . " ]. Setter not found");
                     }
                 }
             } else {
                 if (!$disableMappingExceptions) {
                     throw new Exception("Unable to reverse map element [ " . $element->name . " ] of type [ " . $element->type . " ]. Object_Class_Data type not found. ");
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * @param string $condition
  * @param string $order
  * @param string $orderKey
  * @param string $offset
  * @param string $limit
  * @param string $groupBy
  * @param string $objectClass
  * @return Webservice_Data_Object_List_Item[]
  */
 public function getObjectList($condition = null, $order = null, $orderKey = null, $offset = null, $limit = null, $groupBy = null, $objectClass = null)
 {
     try {
         $params = array();
         if (!empty($condition)) {
             $params["condition"] = $condition;
         }
         if (!empty($order)) {
             $params["order"] = $order;
         }
         if (!empty($orderKey)) {
             $params["orderKey"] = $orderKey;
         }
         if (!empty($offset)) {
             $params["offset"] = $offset;
         }
         if (!empty($limit)) {
             $params["limit"] = $limit;
         }
         if (!empty($groupBy)) {
             $params["groupBy"] = $groupBy;
         }
         $listClassName = "Object_Abstract";
         if (!empty($objectClass)) {
             $listClassName = "Object_" . ucfirst($objectClass);
             if (!Pimcore_Tool::classExists($listClassName)) {
                 $listClassName = "Object_Abstract";
             }
         }
         $list = $listClassName::getList($params);
         $items = array();
         foreach ($list as $object) {
             $item = new Webservice_Data_Object_List_Item();
             $item->id = $object->getId();
             $item->type = $object->getType();
             $items[] = $item;
         }
         return $items;
     } catch (Exception $e) {
         Logger::error($e);
         throw $e;
     }
 }
Ejemplo n.º 9
0
 /**
  * @throws Exception
  * @param  $rootElement
  * @param  $apiKey
  * @param  $path
  * @param  $apiElement
  * @param  bool $overwrite
  * @param  $elementCounter
  * @return Element_Interface
  */
 public function create($rootElement, $apiKey, $path, $apiElement, $overwrite, $elementCounter)
 {
     //correct relative path
     if (strpos($path, "/") !== 0) {
         $path = $rootElement->getFullPath() . "/" . $path;
     }
     $type = $apiElement->type;
     if ($apiElement instanceof Webservice_Data_Asset) {
         $className = "Asset_" . ucfirst($type);
         $parentClassName = "Asset";
         $maintype = "asset";
         $fullPath = $path . $apiElement->filename;
     } else {
         if ($apiElement instanceof Webservice_Data_Object) {
             $maintype = "object";
             if ($type == "object") {
                 $className = "Object_" . ucfirst($apiElement->className);
                 if (!Pimcore_Tool::classExists($className)) {
                     throw new Exception("Unknown class [ " . $className . " ]");
                 }
             } else {
                 $className = "Object_" . ucfirst($type);
             }
             $parentClassName = "Object_Abstract";
             $fullPath = $path . $apiElement->key;
         } else {
             if ($apiElement instanceof Webservice_Data_Document) {
                 $maintype = "document";
                 $className = "Document_" . ucfirst($type);
                 $parentClassName = "Document";
                 $fullPath = $path . $apiElement->key;
             } else {
                 throw new Exception("Unknown import element");
             }
         }
     }
     $existingElement = $className::getByPath($fullPath);
     if ($overwrite && $existingElement) {
         $apiElement->parentId = $existingElement->getParentId();
         return $existingElement;
     }
     $element = new $className();
     $element->setId(null);
     $element->setCreationDate(time());
     if ($element instanceof Asset) {
         $element->setFilename($apiElement->filename);
         $element->setData(base64_decode($apiElement->data));
     } else {
         if ($element instanceof Object_Concrete) {
             $element->setKey($apiElement->key);
             $element->setO_className($apiElement->className);
             $class = Object_Class::getByName($apiElement->className);
             if (!$class instanceof Object_Class) {
                 throw new Exception("Unknown object class [ " . $apiElement->className . " ] ");
             }
             $element->setO_classId($class->getId());
         } else {
             $element->setKey($apiElement->key);
         }
     }
     $this->setModificationParams($element, true);
     $key = $element->getKey();
     if (empty($key) and $apiElement->id == 1) {
         if ($element instanceof Asset) {
             $element->setFilename("home_" . uniqid());
         } else {
             $element->setKey("home_" . uniqid());
         }
     } else {
         if (empty($key)) {
             throw new Exception("Cannot create element without key ");
         }
     }
     $parent = $parentClassName::getByPath($path);
     if (Element_Service::getType($rootElement) == $maintype and $parent) {
         $element->setParentId($parent->getId());
         $apiElement->parentId = $parent->getId();
         $existingElement = $parentClassName::getByPath($parent->getFullPath() . "/" . $element->getKey());
         if ($existingElement) {
             //set dummy key to avoid duplicate paths
             if ($element instanceof Asset) {
                 $element->setFilename(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getFilename());
             } else {
                 $element->setKey(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getKey());
             }
         }
     } else {
         if (Element_Service::getType($rootElement) != $maintype) {
             //this is a related element - try to import it to it's original path or set the parent to home folder
             $potentialParent = $parentClassName::getByPath($path);
             //set dummy key to avoid duplicate paths
             if ($element instanceof Asset) {
                 $element->setFilename(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getFilename());
             } else {
                 $element->setKey(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getKey());
             }
             if ($potentialParent) {
                 $element->setParentId($potentialParent->getId());
                 //set actual id and path for second run
                 $apiElements[$apiKey]["path"] = $potentialParent->getFullPath();
                 $apiElement->parentId = $potentialParent->getId();
             } else {
                 $element->setParentId(1);
                 //set actual id and path for second run
                 $apiElements[$apiKey]["path"] = "/";
                 $apiElement->parentId = 1;
             }
         } else {
             $element->setParentId($rootElement->getId());
             //set actual id and path for second run
             $apiElements[$apiKey]["path"] = $rootElement->getFullPath();
             $apiElement->parentId = $rootElement->getId();
             //set dummy key to avoid duplicate paths
             if ($element instanceof Asset) {
                 $element->setFilename(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getFilename());
             } else {
                 $element->setKey(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getKey());
             }
         }
     }
     //if element exists, make temp key permanent by setting it in apiElement
     if ($parentClassName::getByPath($fullPath)) {
         if ($element instanceof Asset) {
             $apiElement->filename = $element->getFilename();
         } else {
             $apiElement->key = $element->getKey();
         }
     }
     $element->save();
     //todo save type and id for later rollback
     $this->importInfo[Element_Service::getType($element) . "_" . $element->getId()] = array("id" => $element->getId(), "type" => Element_Service::getType($element), "fullpath" => $element->getFullPath());
     return $element;
 }
Ejemplo n.º 10
0
 /**
  * @param array $config
  * @return Object_List
  */
 public static function getList($config = array())
 {
     $className = "Object";
     // get classname
     if (get_called_class() != "Object_Abstract" && get_called_class() != "Object_Concrete") {
         $tmpObject = new static();
         $className = "Object_" . ucfirst($tmpObject->getO_className());
     }
     if (!empty($config["class"])) {
         $className = $config["class"];
     }
     //echo $className;exit;
     if (is_array($config)) {
         if ($className) {
             $listClass = ucfirst($className) . "_List";
             // check for a mapped class
             $listClass = Pimcore_Tool::getModelClassMapping($listClass);
             if (Pimcore_Tool::classExists($listClass)) {
                 $list = new $listClass();
             }
         }
         $list->setValues($config);
         $list->load();
         return $list;
     }
 }
Ejemplo n.º 11
0
 public function load($object, $params = array())
 {
     $classname = "Object_" . ucfirst($object->getClass()->getName()) . "_" . ucfirst($this->getName());
     if (Pimcore_Tool::classExists($classname)) {
         $container = new $classname($object, $this->getName());
         $container->load($object);
         return $container;
     } else {
         return null;
     }
 }
Ejemplo n.º 12
0
 public static function initPlugins()
 {
     // add plugin include paths
     $autoloader = Zend_Loader_Autoloader::getInstance();
     try {
         $pluginConfigs = Pimcore_ExtensionManager::getPluginConfigs();
         if (!empty($pluginConfigs)) {
             $includePaths = array(get_include_path());
             //adding plugin include paths and namespaces
             if (count($pluginConfigs) > 0) {
                 foreach ($pluginConfigs as $p) {
                     if (!Pimcore_ExtensionManager::isEnabled("plugin", $p["plugin"]["pluginName"])) {
                         continue;
                     }
                     if (is_array($p['plugin']['pluginIncludePaths']['path'])) {
                         foreach ($p['plugin']['pluginIncludePaths']['path'] as $path) {
                             $includePaths[] = PIMCORE_PLUGINS_PATH . $path;
                         }
                     } else {
                         if ($p['plugin']['pluginIncludePaths']['path'] != null) {
                             $includePaths[] = PIMCORE_PLUGINS_PATH . $p['plugin']['pluginIncludePaths']['path'];
                         }
                     }
                     if (is_array($p['plugin']['pluginNamespaces']['namespace'])) {
                         foreach ($p['plugin']['pluginNamespaces']['namespace'] as $namespace) {
                             $autoloader->registerNamespace($namespace);
                         }
                     } else {
                         if ($p['plugin']['pluginNamespaces']['namespace'] != null) {
                             $autoloader->registerNamespace($p['plugin']['pluginNamespaces']['namespace']);
                         }
                     }
                 }
             }
             set_include_path(implode(PATH_SEPARATOR, $includePaths));
             $broker = Pimcore_API_Plugin_Broker::getInstance();
             //registering plugins
             foreach ($pluginConfigs as $p) {
                 if (!Pimcore_ExtensionManager::isEnabled("plugin", $p["plugin"]["pluginName"])) {
                     continue;
                 }
                 $jsPaths = array();
                 if (is_array($p['plugin']['pluginJsPaths']['path'])) {
                     $jsPaths = $p['plugin']['pluginJsPaths']['path'];
                 } else {
                     if ($p['plugin']['pluginJsPaths']['path'] != null) {
                         $jsPaths[0] = $p['plugin']['pluginJsPaths']['path'];
                     }
                 }
                 //manipulate path for frontend
                 if (is_array($jsPaths) and count($jsPaths) > 0) {
                     for ($i = 0; $i < count($jsPaths); $i++) {
                         if (is_file(PIMCORE_PLUGINS_PATH . $jsPaths[$i])) {
                             $jsPaths[$i] = "/plugins" . $jsPaths[$i];
                         }
                     }
                 }
                 $cssPaths = array();
                 if (is_array($p['plugin']['pluginCssPaths']['path'])) {
                     $cssPaths = $p['plugin']['pluginCssPaths']['path'];
                 } else {
                     if ($p['plugin']['pluginCssPaths']['path'] != null) {
                         $cssPaths[0] = $p['plugin']['pluginCssPaths']['path'];
                     }
                 }
                 //manipulate path for frontend
                 if (is_array($cssPaths) and count($cssPaths) > 0) {
                     for ($i = 0; $i < count($cssPaths); $i++) {
                         if (is_file(PIMCORE_PLUGINS_PATH . $cssPaths[$i])) {
                             $cssPaths[$i] = "/plugins" . $cssPaths[$i];
                         }
                     }
                 }
                 try {
                     $className = $p['plugin']['pluginClassName'];
                     if (!empty($className) && Pimcore_Tool::classExists($className)) {
                         $plugin = new $className($jsPaths, $cssPaths);
                         if ($plugin instanceof Pimcore_API_Plugin_Abstract) {
                             $broker->registerPlugin($plugin);
                         }
                     }
                 } catch (Exeption $e) {
                     Logger::err("Could not instantiate and register plugin [" . $p['plugin']['pluginClassName'] . "]");
                 }
             }
             Zend_Registry::set("Pimcore_API_Plugin_Broker", $broker);
         }
     } catch (Exception $e) {
         Logger::alert("there is a problem with the plugin configuration");
         Logger::alert($e);
     }
 }
Ejemplo n.º 13
0
 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;
 }
Ejemplo n.º 14
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);
 }
Ejemplo n.º 15
0
 /**
  * Static helper to get an asset by the passed id (returned is not the concrete asset like Asset_Folder!)
  *
  * @param integer $id
  * @return Asset
  */
 public static function getById($id)
 {
     $id = intval($id);
     if ($id < 1) {
         return null;
     }
     $cacheKey = "asset_" . $id;
     try {
         $asset = Zend_Registry::get($cacheKey);
         if (!$asset) {
             throw new Exception("Asset in registry is null");
         }
     } catch (Exception $e) {
         try {
             if (!($asset = Pimcore_Model_Cache::load($cacheKey))) {
                 $asset = new Asset();
                 $asset->getResource()->getById($id);
                 $typeClass = "Asset_" . ucfirst($asset->getType());
                 $typeClass = Pimcore_Tool::getModelClassMapping($typeClass);
                 if (Pimcore_Tool::classExists($typeClass)) {
                     $asset = new $typeClass();
                     Zend_Registry::set($cacheKey, $asset);
                     $asset->getResource()->getById($id);
                     Pimcore_Model_Cache::save($asset, $cacheKey);
                 }
             } else {
                 Zend_Registry::set($cacheKey, $asset);
             }
         } catch (Exception $e) {
             Logger::warning($e);
             return null;
         }
     }
     if (!$asset) {
         return null;
     }
     return $asset;
 }
Ejemplo n.º 16
0
 /**
  * Creates the Placeholder objects and replaces the placeholder string
  * with the rendered content of the placeholder object
  *
  * @param array $placeholderStack
  * @return string
  */
 protected function replacePlaceholdersFromStack($placeholderStack = array())
 {
     $stringReplaced = null;
     if (!empty($placeholderStack)) {
         foreach ($placeholderStack as $placeholder) {
             $placeholderObject = null;
             $websiteClass = self::getWebsiteClassPrefix() . $placeholder['placeholderClass'];
             $pimcoreClass = 'Pimcore_Placeholder_' . $placeholder['placeholderClass'];
             if (is_null($stringReplaced)) {
                 $stringReplaced = $placeholder['contentString'];
             }
             //first try to init the website class -> then the pimcore class
             if (Pimcore_Tool::classExists($websiteClass)) {
                 $placeholderObject = new $websiteClass();
             } elseif (Pimcore_Tool::classExists($pimcoreClass)) {
                 $placeholderObject = new $pimcoreClass();
             }
             if ($placeholderObject instanceof Pimcore_Placeholder_Abstract) {
                 //setting values from placeholder stack to placeholder objects
                 foreach (array_keys($placeholder) as $key) {
                     if ($key == 'placeholderClass') {
                         continue;
                     }
                     $placeholderObject->{'set' . ucfirst($key)}($placeholder[$key]);
                 }
                 $placeholderObject->setLocale();
                 $replaceWith = $placeholderObject->getReplacement();
                 if (!$replaceWith) {
                     $replaceWith = $placeholderObject->getEmptyValue();
                 }
                 $stringReplaced = str_replace($placeholderObject->getPlaceholderString(), $replaceWith, $stringReplaced);
             } else {
                 Logger::warn('Ignoring Placeholder "' . $placeholder['placeholderClass'] . '" -> Class not Found or not an instance of Pimcore_Placeholder_Abstract!');
             }
         }
     }
     return $stringReplaced;
 }
Ejemplo n.º 17
0
 /**
  * Create a new instance of an image tool
  *
  * This method will create a new image tool, defined by the $tool var,
  * which is a string it will call the constructor of the specific tool
  * and return it (if no error occurs)
  *
  * @param string $tool Tool name
  * @param array $options optional Options
  *
  * @return  object New image tool on success or PEAR_Error on failure
  * @access  public
  * @static
  * @see     IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FAILED,
  *          IMAGE_TOOLS_BASE_ERR_CLASS_INVALID,
  *          IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE,
  *          IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED
  */
 function &factory($tool, $options = array())
 {
     if (isset($this) && strtolower(get_class($this)) == 'image_tools') {
         return PEAR::raiseError('This method may only be called statically', IMAGE_TOOLS_BASE_ERR_NONSTATIC_FAILED);
     }
     // Renice the tool name
     $toolParts = @explode('_', $tool);
     if (empty($toolParts) || !is_array($toolParts)) {
         $toolParts[] = $tool;
     }
     foreach ($toolParts as $key => $value) {
         $toolParts[$key] = ucfirst($value);
     }
     $tool = implode('_', $toolParts);
     $toolPath = 'Image/Tools/' . $tool . '.php';
     // Include the tool class
     require_once $toolPath;
     $className = "Image_Tools_{$tool}";
     if (!Pimcore_Tool::classExists($className)) {
         return PEAR::raiseError('File not found ' . $toolPath . ' or undefined class ' . $className, IMAGE_TOOLS_BASE_ERR_CLASS_INVALID);
     }
     @($obj =& new $className($options));
     if (!is_object($obj) || !is_a($obj, $className)) {
         return PEAR::raiseError('Could not instanciate image tool ' . $className, IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FAILED);
     }
     $res = $obj->set($options);
     if (PEAR::isError($res)) {
         return $res;
     }
     return $obj;
 }
Ejemplo n.º 18
0
 /**
  *
  */
 public function content()
 {
     // create info object and assign it to the view
     $info = null;
     try {
         $info = new Document_Tag_Area_Info();
         $info->setId($this->currentIndex["type"]);
         $info->setIndex($this->current);
         $info->setPath(str_replace(PIMCORE_DOCUMENT_ROOT, "", Pimcore_ExtensionManager::getPathForExtension($this->currentIndex["type"], "brick")));
         $info->setConfig(Pimcore_ExtensionManager::getBrickConfig($this->currentIndex["type"]));
     } catch (Exception $e) {
         $info = null;
     }
     if ($this->getView() instanceof Zend_View) {
         $this->getView()->brick = $info;
         $areas = $this->getAreaDirs();
         $view = $areas[$this->currentIndex["type"]] . "/view.php";
         $action = $areas[$this->currentIndex["type"]] . "/action.php";
         $edit = $areas[$this->currentIndex["type"]] . "/edit.php";
         $options = $this->getOptions();
         $params = array();
         if (is_array($options["params"]) && array_key_exists($this->currentIndex["type"], $options["params"])) {
             if (is_array($options["params"][$this->currentIndex["type"]])) {
                 $params = $options["params"][$this->currentIndex["type"]];
             }
         }
         // assign parameters to view
         foreach ($params as $key => $value) {
             $this->getView()->assign($key, $value);
         }
         // check for action file
         if (is_file($action)) {
             include_once $action;
             $actionClassname = "Document_Tag_Area_" . ucfirst($this->currentIndex["type"]);
             if (Pimcore_Tool::classExists($actionClassname)) {
                 $actionObj = new $actionClassname();
                 if ($actionObj instanceof Document_Tag_Area_Abstract) {
                     $actionObj->setView($this->getView());
                     $areaConfig = new Zend_Config_Xml($areas[$this->currentIndex["type"]] . "/area.xml");
                     $actionObj->setConfig($areaConfig);
                     // params
                     $params = array_merge($this->view->getAllParams(), $params);
                     $actionObj->setParams($params);
                     if ($info) {
                         $actionObj->setBrick($info);
                     }
                     if (method_exists($actionObj, "action")) {
                         $actionObj->action();
                     }
                 }
             }
         }
         if (is_file($view)) {
             $editmode = $this->getView()->editmode;
             //echo '<div class="pimcore_area_' . $this->currentIndex["type"] . ' pimcore_area_content">';
             if (is_file($edit) && $editmode) {
                 echo '<div class="pimcore_area_edit_button"></div>';
                 $this->getView()->editmode = false;
             }
             $this->getView()->template($view);
             if (is_file($edit) && $editmode) {
                 $this->getView()->editmode = true;
                 echo '<div class="pimcore_area_editmode">';
                 $this->getView()->template($edit);
                 echo '</div>';
             }
             //echo '</div>';
         }
     }
     $this->current++;
 }
Ejemplo n.º 19
0
 /**
  * @static
  * @param  $sourceClassName
  * @return string
  */
 public static function getModelClassMapping($sourceClassName)
 {
     $targetClassName = $sourceClassName;
     if ($map = Pimcore_Config::getModelClassMappingConfig()) {
         $tmpClassName = $map->{$sourceClassName};
         if ($tmpClassName) {
             if (Pimcore_Tool::classExists($tmpClassName)) {
                 if (is_subclass_of($tmpClassName, $sourceClassName)) {
                     $targetClassName = $tmpClassName;
                 }
             }
         }
     }
     return $targetClassName;
 }