public function translationsAction() { $admin = $this->_getParam("admin"); if ($this->getUser()->isAllowed("translations")) { // clear translation cache Pimcore_Model_Cache::clearTags(array("translator", "translate")); if ($this->_getParam("data")) { if ($this->_getParam("xaction") == "destroy") { $key = Zend_Json::decode($this->_getParam("data")); if ($admin) { $t = Translation_Admin::getByKey($key); } else { $t = Translation_Website::getByKey($key); } $t->delete(); $this->_helper->json(array("success" => true, "data" => array())); } else { if ($this->_getParam("xaction") == "update") { $data = Zend_Json::decode($this->_getParam("data")); if ($admin) { $t = Translation_Admin::getByKey($data["key"]); } else { $t = Translation_Website::getByKey($data["key"]); } foreach ($data as $key => $value) { if ($key != "key") { $t->addTranslation($key, $value); } } if ($data["key"]) { $t->setKey($data["key"]); } $t->save(); $return = array_merge(array("key" => $t->getKey(), "date" => $t->getDate()), $t->getTranslations()); $this->_helper->json(array("data" => $return, "success" => true)); } else { if ($this->_getParam("xaction") == "create") { $data = Zend_Json::decode($this->_getParam("data")); if ($admin) { $t = new Translation_Admin(); } else { $t = new Translation_Website(); } $t->setKey($data["key"]); $t->setDate(time()); foreach ($data as $key => $value) { if ($key != "key" && $key != "date") { $t->addTranslation($key, $value); } } $t->save(); $return = array_merge(array("key" => $t->getKey(), "date" => $t->getDate()), $t->getTranslations()); $this->_helper->json(array("data" => $return, "success" => true)); } } } } else { // get list of types if ($admin) { $list = new Translation_Admin_List(); } else { $list = new Translation_Website_List(); } $list->setOrder("asc"); $list->setOrderKey("key"); if ($this->_getParam("dir")) { $list->setOrder($this->_getParam("dir")); } if ($this->_getParam("sort")) { $list->setOrderKey($this->_getParam("sort")); } $list->setLimit($this->_getParam("limit")); $list->setOffset($this->_getParam("start")); if ($this->_getParam("filter")) { $filterTerm = $list->quote("%" . strtolower($this->_getParam("filter")) . "%"); $list->setCondition("lower(`key`) LIKE " . $filterTerm . " OR `text` LIKE " . $filterTerm); } $list->load(); $translations = array(); foreach ($list->getTranslations() as $t) { $translations[] = array_merge(array("key" => $t->getKey(), "date" => $t->getDate()), $t->getTranslations()); } $this->_helper->json(array("data" => $translations, "success" => true, "total" => $list->getTotalCount())); } } else { Logger::err("user [" . $this->getUser()->getId() . "] attempted to access translations, but has no permission to do so."); } $this->_helper->json(false); }