作者:pawansgi9
项目:pimcore
/**
* @return Tool\User
* @throws \Exception
*/
public function getUser()
{
if ($user = Tool\Admin::getCurrentUser()) {
return $user;
}
throw new \Exception("Webservice instantiated, but no user present");
}
作者:yonetic
项目:pimcore-coreshop-dem
/**
* @param $class
* @param $json
* @return bool
*/
public static function importClassDefinitionFromJson($class, $json, $throwException = false)
{
$userId = 0;
$user = \Pimcore\Tool\Admin::getCurrentUser();
if ($user) {
$userId = $user->getId();
}
$importData = \Zend_Json::decode($json);
// set layout-definition
$layout = self::generateLayoutTreeFromArray($importData["layoutDefinitions"], $throwException);
if ($layout === false) {
return false;
}
$class->setLayoutDefinitions($layout);
// set properties of class
$class->setModificationDate(time());
$class->setUserModification($userId);
$class->setIcon($importData["icon"]);
$class->setAllowInherit($importData["allowInherit"]);
$class->setAllowVariants($importData["allowVariants"]);
$class->setShowVariants($importData["showVariants"]);
$class->setParentClass($importData["parentClass"]);
$class->setUseTraits($importData["useTraits"]);
$class->setPreviewUrl($importData["previewUrl"]);
$class->setPropertyVisibility($importData["propertyVisibility"]);
$class->save();
return true;
}
作者:rolandstol
项目:pimcor
/**
* this is a hack for import see: http://www.pimcore.org/issues/browse/PIMCORE-790
* @param array
* @return array
*/
protected function correctClasses($classes)
{
// this is the new method with Ext.form.MultiSelect
/**
* @extjs6
* @todo this need to be refactored when extjs3 support is removed
*/
if (is_string($classes) && !empty($classes) || \Pimcore\Tool\Admin::isExtJS6() && is_array($classes)) {
if (!\Pimcore\Tool\Admin::isExtJS6()) {
$classParts = explode(",", $classes);
} else {
$classParts = $classes;
}
$classes = array();
foreach ($classParts as $class) {
if (is_array($class)) {
$classes[] = $class;
} else {
if ($class) {
$classes[] = array("classes" => $class);
}
}
}
}
// this was the legacy method with Ext.SuperField
if (is_array($classes) && array_key_exists("classes", $classes)) {
$classes = array($classes);
}
if (!is_array($classes)) {
$classes = array();
}
return $classes;
}
作者:solvera
项目:pimcor
/**
* @param \Zend_Controller_Request_Abstract $request
*/
public function routeStartup(\Zend_Controller_Request_Abstract $request)
{
$maintenance = false;
$file = \Pimcore\Tool\Admin::getMaintenanceModeFile();
if (is_file($file)) {
$conf = (include $file);
if (isset($conf["sessionId"])) {
if ($conf["sessionId"] != $_COOKIE["pimcore_admin_sid"]) {
$maintenance = true;
}
} else {
@unlink($file);
}
}
// do not activate the maintenance for the server itself
// this is to avoid problems with monitoring agents
$serverIps = ["127.0.0.1"];
if ($maintenance && !in_array(\Pimcore\Tool::getClientIp(), $serverIps)) {
header("HTTP/1.1 503 Service Temporarily Unavailable", 503);
$file = PIMCORE_PATH . "/static/html/maintenance.html";
$customFile = PIMCORE_CUSTOM_CONFIGURATION_DIRECTORY . "/maintenance.html";
if (file_exists($customFile)) {
$file = $customFile;
}
echo file_get_contents($file);
exit;
}
}
作者:solvera
项目:pimcor
public function saveAction()
{
try {
if ($this->getParam("id")) {
$link = Document\Hardlink::getById($this->getParam("id"));
$this->setValuesToDocument($link);
$link->setModificationDate(time());
$link->setUserModification($this->getUser()->getId());
if ($this->getParam("task") == "unpublish") {
$link->setPublished(false);
}
if ($this->getParam("task") == "publish") {
$link->setPublished(true);
}
// only save when publish or unpublish
if ($this->getParam("task") == "publish" && $link->isAllowed("publish") || $this->getParam("task") == "unpublish" && $link->isAllowed("unpublish")) {
$link->save();
$this->_helper->json(["success" => true]);
}
}
} catch (\Exception $e) {
\Logger::log($e);
if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
$this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]);
}
throw $e;
}
$this->_helper->json(false);
}
作者:ChristophWurs
项目:pimcor
public static function getRecordIdForGridRequest($param)
{
if (!\Pimcore\Tool\Admin::isExtJS6() && is_numeric($param)) {
return intval($param);
} else {
$param = json_decode($param, true);
return $param['id'];
}
}
作者:solvera
项目:pimcor
private function checkUserPermission($permission)
{
if ($user = Tool\Admin::getCurrentUser()) {
if ($user->isAllowed($permission)) {
return;
}
}
$this->getResponse()->setHttpResponseCode(403);
$this->encoder->encode(["success" => false, "msg" => "not allowed"]);
}
作者:elavarasan
项目:pimcor
/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
parent::initialize($input, $output);
$this->input = $input;
$this->output = $output;
// use Console\Dumper for nice debug output
$this->dumper = new Dumper($this->output);
// skip if maintenance mode is on and the flag is not set
if (Admin::isInMaintenanceMode() && !$input->getOption('ignore-maintenance-mode')) {
throw new \RuntimeException('In maintenance mode - set the flag --ignore-maintenance-mode to force execution!');
}
}
作者:emanuel-londo
项目:pimcor
/**
* @param $id
* @param bool $create
* @param bool $returnIdIfEmpty
* @param null $language
* @return array
* @throws \Exception
* @throws \Zend_Exception
*/
public static function getByKeyLocalized($id, $create = false, $returnIdIfEmpty = false, $language = null)
{
if ($user = Tool\Admin::getCurrentUser()) {
$language = $user->getLanguage();
} elseif ($user = Tool\Authentication::authenticateSession()) {
$language = $user->getLanguage();
} elseif (\Zend_Registry::isRegistered("Zend_Locale")) {
$language = (string) \Zend_Registry::get("Zend_Locale");
}
if (!in_array($language, Tool\Admin::getLanguages())) {
$config = \Pimcore\Config::getSystemConfig();
$language = $config->general->language;
}
return self::getByKey($id, $create, $returnIdIfEmpty)->getTranslation($language);
}
作者:pimcor
项目:pimcor
public function updateAction()
{
$report = CustomReport\Config::getByName($this->getParam("name"));
$data = \Zend_Json::decode($this->getParam("configuration"));
if (\Pimcore\Tool\Admin::isExtJS6() && !is_array($data["yAxis"])) {
$data["yAxis"] = strlen($data["yAxis"]) ? [$data["yAxis"]] : [];
}
foreach ($data as $key => $value) {
$setter = "set" . ucfirst($key);
if (method_exists($report, $setter)) {
$report->{$setter}($value);
}
}
$report->save();
$this->_helper->json(["success" => true]);
}
作者:putzfloria
项目:Pimcore-Frontend-Logi
public function init()
{
parent::init();
$pimUser = false;
if (\Pimcore\Tool::isFrontentRequestByAdmin()) {
$pimUser = \Pimcore\Tool\Admin::getCurrentUser();
if ($pimUser) {
//echo "IS ADMIN";
}
}
$identity = \Zend_Auth::getInstance()->getIdentity();
if (!$identity && !$pimUser or $this->getParam('oid') != $identity['oid']) {
$this->redirect("/");
} else {
// login ok
}
}
作者:cannoner
项目:pimcor
/**
* Moves a file/directory
*
* @param string $sourcePath
* @param string $destinationPath
* @return void
*/
public function move($sourcePath, $destinationPath)
{
$nameParts = explode("/", $sourcePath);
$nameParts[count($nameParts) - 1] = File::getValidFilename($nameParts[count($nameParts) - 1]);
$sourcePath = implode("/", $nameParts);
$nameParts = explode("/", $destinationPath);
$nameParts[count($nameParts) - 1] = File::getValidFilename($nameParts[count($nameParts) - 1]);
$destinationPath = implode("/", $nameParts);
try {
if (dirname($sourcePath) == dirname($destinationPath)) {
$asset = null;
if ($asset = Asset::getByPath("/" . $destinationPath)) {
// If we got here, this means the destination exists, and needs to be overwritten
$sourceAsset = Asset::getByPath("/" . $sourcePath);
$asset->setData($sourceAsset->getData());
$sourceAsset->delete();
}
// see: Asset\WebDAV\File::delete() why this is necessary
$log = Asset\WebDAV\Service::getDeleteLog();
if (!$asset && array_key_exists("/" . $destinationPath, $log)) {
$asset = \Pimcore\Tool\Serialize::unserialize($log["/" . $destinationPath]["data"]);
if ($asset) {
$sourceAsset = Asset::getByPath("/" . $sourcePath);
$asset->setData($sourceAsset->getData());
$sourceAsset->delete();
}
}
if (!$asset) {
$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());
}
$user = \Pimcore\Tool\Admin::getCurrentUser();
$asset->setUserModification($user->getId());
$asset->save();
} catch (\Exception $e) {
\Logger::error($e);
}
}
作者:solvera
项目:pimcor
/**
* Creates a note for an action with a transition
* @param Element\AbstractElement $element
* @param string $type
* @param string $title
* @param string $description
* @param array $noteData
* @return Element\Note $note
*/
public static function createActionNote($element, $type, $title, $description, $noteData, $user = null)
{
//prepare some vars for creating the note
if (!$user) {
$user = \Pimcore\Tool\Admin::getCurrentUser();
}
$note = new Element\Note();
$note->setElement($element);
$note->setDate(time());
$note->setType($type);
$note->setTitle($title);
$note->setDescription($description);
$note->setUser($user->getId());
if (is_array($noteData)) {
foreach ($noteData as $row) {
$note->addData($row['key'], $row['type'], $row['value']);
}
}
$note->save();
return $note;
}
作者:solvera
项目:pimcor
/**
* Fired before information is sent back to the admin UI about an element
* @param \Zend_EventManager_Event $e
* @throws \Exception
*/
public static function adminElementGetPreSendData($e)
{
$element = self::extractElementFromEvent($e);
$returnValueContainer = $e->getParam('returnValueContainer');
$data = $returnValueContainer->getData();
//create a new namespace for WorkflowManagement
//set some defaults
$data['workflowManagement'] = ['hasWorkflowManagement' => false];
if (Workflow\Manager::elementCanAction($element)) {
$data['workflowManagement']['hasWorkflowManagement'] = true;
//see if we can change the layout
$currentUser = Admin::getCurrentUser();
$manager = Workflow\Manager\Factory::getManager($element, $currentUser);
$data['workflowManagement']['workflowName'] = $manager->getWorkflow()->getName();
//get the state and status
$state = $manager->getElementState();
$data['workflowManagement']['state'] = $manager->getWorkflow()->getStateConfig($state);
$status = $manager->getElementStatus();
$data['workflowManagement']['status'] = $manager->getWorkflow()->getStatusConfig($status);
if ($element instanceof ConcreteObject) {
$workflowLayoutId = $manager->getObjectLayout();
//check for !is_null here as we might want to specify 0 in the workflow config
if (!is_null($workflowLayoutId)) {
//load the new layout into the object container
$validLayouts = Object\Service::getValidLayouts($element);
//check that the layout id is valid before trying to load
if (!empty($validLayouts)) {
//todo check user permissions again
if ($validLayouts && $validLayouts[$workflowLayoutId]) {
$customLayout = ClassDefinition\CustomLayout::getById($workflowLayoutId);
$customLayoutDefinition = $customLayout->getLayoutDefinitions();
Object\Service::enrichLayoutDefinition($customLayoutDefinition, $e->getParam('object'));
$data["layout"] = $customLayoutDefinition;
}
}
}
}
}
$returnValueContainer->setData($data);
}
作者:Gerhard1
项目:pimcor
/**
* this is a hack for import see: http://www.pimcore.org/issues/browse/PIMCORE-790
* @param array
* @return array
*/
protected function correctClasses($classes)
{
// this is the new method with Ext.form.MultiSelect
if (is_string($classes) && !empty($classes) || \Pimcore\Tool\Admin::isExtJS5() && is_array($classes)) {
if (!\Pimcore\Tool\Admin::isExtJS5()) {
$classParts = explode(",", $classes);
} else {
$classParts = $classes;
}
$classes = array();
foreach ($classParts as $class) {
$classes[] = array("classes" => $class);
}
}
// this was the legacy method with Ext.SuperField
if (is_array($classes) && array_key_exists("classes", $classes)) {
$classes = array($classes);
}
if (!is_array($classes)) {
$classes = array();
}
return $classes;
}
作者:Gerhard1
项目:pimcor
/**
* @param \Zend_Controller_Request_Abstract $request
*/
public function routeStartup(\Zend_Controller_Request_Abstract $request)
{
$maintenance = false;
$file = \Pimcore\Tool\Admin::getMaintenanceModeFile();
if (is_file($file)) {
$conf = new \Zend_Config_Xml($file);
if ($conf->sessionId) {
if ($conf->sessionId != $_COOKIE["pimcore_admin_sid"]) {
$maintenance = true;
}
} else {
@unlink($file);
}
}
// do not activate the maintenance for the server itself
// this is to avoid problems with monitoring agents
$serverIps = array("127.0.0.1");
if ($maintenance && !in_array(\Pimcore\Tool::getClientIp(), $serverIps)) {
header("HTTP/1.1 503 Service Temporarily Unavailable", 503);
echo file_get_contents(PIMCORE_PATH . "/static/html/maintenance.html");
exit;
}
}
作者:emanuel-londo
项目:pimcor
/**
* Constructor.
*
* @param string $name The name of the application
* @param string $version The version of the application
*
* @api
*/
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
{
parent::__construct('Pimcore CLI', Version::getVersion());
// init default autoload namespaces
$this->initDefaultAutoloadNamespaces();
// allow to register commands here (e.g. through plugins)
\Pimcore::getEventManager()->trigger('system.console.init', $this);
$dispatcher = new EventDispatcher();
$this->setDispatcher($dispatcher);
$dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) {
if ($event->getInput()->getOption("maintenance-mode")) {
// enable maintenance mode if requested
$maintenanceModeId = 'cache-warming-dummy-session-id';
$event->getOutput()->writeln('Activating maintenance mode with ID <comment>' . $maintenanceModeId . '</comment> ...');
Admin::activateMaintenanceMode($maintenanceModeId);
}
});
$dispatcher->addListener(ConsoleEvents::TERMINATE, function (ConsoleTerminateEvent $event) {
if ($event->getInput()->getOption("maintenance-mode")) {
$event->getOutput()->writeln('Deactivating maintenance mode...');
Admin::deactivateMaintenanceMode();
}
});
}
作者:sfi
项目:pimcor
/**
* @param array
* @return void $assetTypes
*/
public function setAssetTypes($assetTypes)
{
// this is the new method with Ext.form.MultiSelect
if (is_string($assetTypes) && !empty($assetTypes) || \Pimcore\Tool\Admin::isExtJS6() && is_array($assetTypes)) {
if (!\Pimcore\Tool\Admin::isExtJS6()) {
$parts = explode(",", $assetTypes);
} else {
$parts = $assetTypes;
}
$assetTypes = array();
foreach ($parts as $type) {
$assetTypes[] = array("assetTypes" => $type);
}
}
$this->assetTypes = $assetTypes;
return $this;
}
作者:emanuel-londo
项目:pimcor
public function gridProxyAction()
{
if ($this->getParam("language")) {
$this->setLanguage($this->getParam("language"), true);
}
if ($this->getParam("data")) {
if ($this->getParam("xaction") == "update") {
try {
$data = \Zend_Json::decode($this->getParam("data"));
// save
$object = Object::getById($data["id"]);
/** @var Object\ClassDefinition $class */
$class = $object->getClass();
if (!$object->isAllowed("publish")) {
throw new \Exception("Permission denied. You don't have the rights to save this object.");
}
$user = Tool\Admin::getCurrentUser();
if (!$user->isAdmin()) {
$languagePermissions = $object->getPermissions("lEdit", $user);
$languagePermissions = explode(",", $languagePermissions["lEdit"]);
}
$objectData = array();
foreach ($data as $key => $value) {
$parts = explode("~", $key);
if (substr($key, 0, 1) == "~") {
$type = $parts[1];
$field = $parts[2];
$keyid = $parts[3];
$getter = "get" . ucfirst($field);
$setter = "set" . ucfirst($field);
$keyValuePairs = $object->{$getter}();
if (!$keyValuePairs) {
$keyValuePairs = new Object\Data\KeyValue();
$keyValuePairs->setObjectId($object->getId());
$keyValuePairs->setClass($object->getClass());
}
$keyValuePairs->setPropertyWithId($keyid, $value, true);
$object->{$setter}($keyValuePairs);
} elseif (count($parts) > 1) {
$brickType = $parts[0];
$brickKey = $parts[1];
$brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType);
$fieldGetter = "get" . ucfirst($brickField);
$brickGetter = "get" . ucfirst($brickType);
$valueSetter = "set" . ucfirst($brickKey);
$brick = $object->{$fieldGetter}()->{$brickGetter}();
if (empty($brick)) {
$classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType);
$brickSetter = "set" . ucfirst($brickType);
$brick = new $classname($object);
$object->{$fieldGetter}()->{$brickSetter}($brick);
}
$brick->{$valueSetter}($value);
} else {
if (!$user->isAdmin() && $languagePermissions) {
$fd = $class->getFieldDefinition($key);
if (!$fd) {
// try to get via localized fields
$localized = $class->getFieldDefinition("localizedfields");
if ($localized instanceof Object\ClassDefinition\Data\Localizedfields) {
$field = $localized->getFieldDefinition($key);
if ($field) {
$currentLocale = (string) \Zend_Registry::get("Zend_Locale");
if (!in_array($currentLocale, $languagePermissions)) {
continue;
}
}
}
}
}
$objectData[$key] = $value;
}
}
$object->setValues($objectData);
$object->save();
$this->_helper->json(array("data" => Object\Service::gridObjectData($object, $this->getParam("fields")), "success" => true));
} catch (\Exception $e) {
$this->_helper->json(array("success" => false, "message" => $e->getMessage()));
}
}
} else {
// get list of objects
$folder = Object::getById($this->getParam("folderId"));
$class = Object\ClassDefinition::getById($this->getParam("classId"));
$className = $class->getName();
$colMappings = array("filename" => "o_key", "fullpath" => array("o_path", "o_key"), "id" => "o_id", "published" => "o_published", "modificationDate" => "o_modificationDate", "creationDate" => "o_creationDate");
$start = 0;
$limit = 20;
$orderKey = "o_id";
$order = "ASC";
$fields = array();
$bricks = array();
if ($this->getParam("fields")) {
$fields = $this->getParam("fields");
foreach ($fields as $f) {
$parts = explode("~", $f);
$sub = substr($f, 0, 1);
if (substr($f, 0, 1) == "~") {
// $type = $parts[1];
// $field = $parts[2];
//.........这里部分代码省略.........
作者:ChristophWurs
项目:pimcor
/**
* @param resource $data
* @throws DAV\Exception\Forbidden
* @throws \Exception
*/
function put($data)
{
if ($this->asset->isAllowed("publish")) {
// read from resource -> default for SabreDAV
$tmpFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/asset-dav-tmp-file-" . uniqid();
file_put_contents($tmpFile, $data);
$file = fopen($tmpFile, "r+");
$user = AdminTool::getCurrentUser();
$this->asset->setUserModification($user->getId());
$this->asset->setStream($file);
$this->asset->save();
fclose($file);
unlink($tmpFile);
} else {
throw new DAV\Exception\Forbidden();
}
}