Beispiel #1
0
 public static function lock($cid, $ctype)
 {
     // try to get user
     if (!($user = Pimcore_Tool_Admin::getCurrentUser())) {
         return false;
     }
     $lock = new self();
     $lock->setCid($cid);
     $lock->setCtype($ctype);
     $lock->setDate(time());
     $lock->setUserId($user->getId());
     $lock->setSessionId(session_id());
     $lock->save();
     return $lock;
 }
 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);
         }
     }
     if ($maintenance) {
         header("HTTP/1.1 503 Service Temporarily Unavailable", 503);
         echo file_get_contents(PIMCORE_PATH . "/static/html/maintenance.html");
         exit;
     }
 }
Beispiel #3
0
 public function translate($key)
 {
     $translated = $key;
     if ($key) {
         $locale = $_REQUEST["systemLocale"];
         if ($locale) {
             try {
                 $translation = Translation_Admin::getByKey($key);
             } catch (Exception $e) {
             }
             if ($translation instanceof Translation_Admin) {
                 if ($translation->getTranslation($locale)) {
                     $translated = $translation->getTranslation($locale);
                 } else {
                     if (PIMCORE_DEBUG) {
                         $translated = "+" . $key . "+";
                     }
                 }
             } else {
                 $t = new Translation_Admin();
                 $availableLanguages = Pimcore_Tool_Admin::getLanguages();
                 $t->setKey($key);
                 $t->setDate(time());
                 foreach ($availableLanguages as $lang) {
                     $t->addTranslation($lang, "");
                 }
                 try {
                     $t->save();
                 } catch (Exception $e) {
                     Logger::debug(get_class($this), ": could not save new translation for key [ {$key} ]");
                 }
             }
         }
     }
     return $translated;
 }
Beispiel #4
0
 public static function initTranslations($instance)
 {
     //add translations to registry
     $coreLanguageFile = Pimcore_Tool_Admin::getLanguageFile("en");
     $translator = new Zend_Translate('csv', $coreLanguageFile, 'en', array('delimiter' => ','));
     $availableLanguages = Pimcore_Tool_Admin::getLanguages();
     foreach ($availableLanguages as $lang) {
         if ($lang != "en") {
             $languageFile = Pimcore_Tool_Admin::getLanguageFile($lang);
             $translator->addTranslation($languageFile, $lang);
         }
     }
     if (Zend_Registry::isRegistered("Zend_Locale")) {
         $locale = Zend_Registry::get("Zend_Locale");
         @$translator->setLocale($locale->getLanguage());
     }
     Zend_Registry::set("Zend_Translate", $translator);
     if ($instance) {
         $instance->setTranslator($translator);
     }
 }
 public function getAvailableAdminLanguagesAction()
 {
     $langs = array();
     $availableLanguages = Pimcore_Tool_Admin::getLanguages();
     foreach ($availableLanguages as $lang) {
         $langs[] = array("language" => $lang, "display" => Zend_Locale::getTranslation($lang, 'language', $lang));
     }
     $this->_helper->json($langs);
 }
Beispiel #6
0
        <?php 
    }
    ?>
    <?php 
} else {
    ?>
        <?php 
    $scriptContents = "";
    foreach ($scripts as $scriptUrl) {
        if (is_file(PIMCORE_PATH . "/static/js/" . $scriptUrl)) {
            $scriptContents .= file_get_contents(PIMCORE_PATH . "/static/js/" . $scriptUrl) . "\n\n\n";
        }
    }
    ?>
        <script type="text/javascript" src="<?php 
    echo Pimcore_Tool_Admin::getMinimizedScriptPath($scriptContents);
    ?>
?_dc=<?php 
    echo Pimcore_Version::$revision;
    ?>
"></script>
    <?php 
}
?>

    <!-- modified plugins -->
    <?php 
foreach ($modifiedPlugins as $scriptUrl) {
    ?>
        <script type="text/javascript" src="/pimcore/static/js/<?php 
    echo $scriptUrl;
Beispiel #7
0
 /**
  * Download language files for a specific language for pimcore core and all plugins or
  * download language files for all existing system languages for pimcore core and plugins if parameter is null
  * @static
  * @param  $language
  * @return bool
  */
 public static function downloadLanguage($lang = null)
 {
     $languages = Pimcore_Tool_Admin::getLanguages();
     if (!empty($lang)) {
         $languages = array($lang);
     } else {
         //omit core language
         $additonalLanguages = array();
         foreach ($languages as $lang) {
             if ($lang != "en") {
                 $additonalLanguages[] = $lang;
             }
         }
         $languages = $additonalLanguages;
     }
     //directory for additional languages
     $langDir = PIMCORE_WEBSITE_PATH . "/var/config/texts";
     if (!is_dir($langDir)) {
         mkdir($langDir, 0755, true);
     }
     $success = is_dir($langDir);
     if ($success) {
         if (is_array($languages)) {
             foreach ($languages as $language) {
                 //TODO: remove hard coded
                 $src = "http://www.pimcore.org/?controller=translation&action=download&language=" . $language;
                 $data = Pimcore_Tool::getHttpData($src);
                 if (!empty($language) and !empty($data)) {
                     try {
                         $languageFile = $langDir . "/" . $language . ".csv";
                         $fh = fopen($languageFile, 'w');
                         fwrite($fh, $data);
                         fclose($fh);
                     } catch (Exception $e) {
                         Logger::error("could not download language file");
                         Logger::error($e);
                         $success = false;
                     }
                 }
             }
         }
     } else {
         Logger::warning("Pimcore_Update: Could not create language dir [  {$langDir} ]");
     }
     return $success;
 }
Beispiel #8
0
    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {
        // add scripts to editmode
        $editmodeLibraries = array("/pimcore/static/js/pimcore/namespace.js", "/pimcore/static/js/lib/prototype-light.js", "/pimcore/static/js/lib/jquery-1.4.2.min.js", "/pimcore/static/js/lib/ext/adapter/jquery/ext-jquery-adapter-debug.js", "/pimcore/static/js/lib/ext/ext-all-debug.js", "/pimcore/static/js/lib/ext-plugins/ux/Spinner.js", "/pimcore/static/js/lib/ext-plugins/ux/SpinnerField.js", "/pimcore/static/js/lib/ext-plugins/ux/MultiSelect.js", "/pimcore/static/js/lib/ext-plugins/ux/Portal.js", "/pimcore/static/js/lib/ext-plugins/ux/PortalColumn.js", "/pimcore/static/js/lib/ext-plugins/ux/Portlet.js", "/pimcore/static/js/lib/ext-plugins/GridRowOrder/roworder.js", "/pimcore/static/js/lib/ckeditor/ckeditor.js", "/pimcore/static/js/pimcore/libfixes.js");
        $editmodeScripts = array("/pimcore/static/js/pimcore/functions.js", "/pimcore/static/js/pimcore/document/edit/helper.js", "/pimcore/static/js/pimcore/document/edit/dnd.js", "/pimcore/static/js/pimcore/document/tag.js", "/pimcore/static/js/pimcore/document/tags/block.js", "/pimcore/static/js/pimcore/document/tags/date.js", "/pimcore/static/js/pimcore/document/tags/href.js", "/pimcore/static/js/pimcore/document/tags/multihref.js", "/pimcore/static/js/pimcore/document/tags/checkbox.js", "/pimcore/static/js/pimcore/document/tags/image.js", "/pimcore/static/js/pimcore/document/tags/input.js", "/pimcore/static/js/pimcore/document/tags/link.js", "/pimcore/static/js/pimcore/document/tags/select.js", "/pimcore/static/js/pimcore/document/tags/snippet.js", "/pimcore/static/js/pimcore/document/tags/textarea.js", "/pimcore/static/js/pimcore/document/tags/numeric.js", "/pimcore/static/js/pimcore/document/tags/wysiwyg.js", "/pimcore/static/js/pimcore/document/tags/renderlet.js", "/pimcore/static/js/pimcore/document/tags/table.js", "/pimcore/static/js/pimcore/document/tags/video.js", "/pimcore/static/js/pimcore/document/tags/multiselect.js", "/pimcore/static/js/pimcore/document/tags/areablock.js", "/pimcore/static/js/pimcore/document/edit/helper.js");
        $conf = Pimcore_Config::getSystemConfig();
        $themeUrl = "/pimcore/static/js/lib/ext/resources/css/xtheme-blue.css";
        if ($conf->general->theme) {
            $themeUrl = $conf->general->theme;
        }
        $editmodeStylesheets = array("/pimcore/static/js/lib/ext/resources/css/ext-all.css", $themeUrl, "/pimcore/static/css/icons.css", "/pimcore/static/css/editmode.css", "/pimcore/static/js/lib/ext-plugins/ux/css/Spinner.css", "/pimcore/static/js/lib/ext-plugins/ux/css/MultiSelect.css", "/pimcore/static/js/lib/ext-plugins/ux/css/Portal.css");
        //add plugin editmode JS and CSS
        try {
            $pluginConfigs = Pimcore_ExtensionManager::getPluginConfigs();
            $jsPaths = array();
            $cssPaths = array();
            if (!empty($pluginConfigs)) {
                //registering plugins
                foreach ($pluginConfigs as $p) {
                    if (is_array($p['plugin']['pluginDocumentEditmodeJsPaths']['path'])) {
                        $jsPaths = $p['plugin']['pluginDocumentEditmodeJsPaths']['path'];
                    } else {
                        if ($p['plugin']['pluginDocumentEditmodeJsPaths']['path'] != null) {
                            $jsPaths[0] = $p['plugin']['pluginDocumentEditmodeJsPaths']['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];
                            }
                        }
                    }
                    if (is_array($p['plugin']['pluginDocumentEditmodeCssPaths']['path'])) {
                        $cssPaths = $p['plugin']['pluginDocumentEditmodeCssPaths']['path'];
                    } else {
                        if ($p['plugin']['pluginDocumentEditmodeCssPaths']['path'] != null) {
                            $cssPaths[0] = $p['plugin']['pluginDocumentEditmodeCssPaths']['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];
                            }
                        }
                    }
                }
            }
            $editmodeScripts = array_merge($editmodeScripts, $jsPaths);
            $editmodeStylesheets = array_merge($editmodeStylesheets, $cssPaths);
        } catch (Exception $e) {
            Logger::alert("there is a problem with the plugin configuration");
            Logger::alert($e);
        }
        $editmodeHeadHtml = "\n\n\n<!-- pimcore editmode -->\n";
        // include stylesheets
        foreach ($editmodeStylesheets as $sheet) {
            $editmodeHeadHtml .= '<link rel="stylesheet" type="text/css" href="' . $sheet . '?_dc=' . Pimcore_Version::$revision . '" />';
            $editmodeHeadHtml .= "\n";
        }
        // include script libraries
        foreach ($editmodeLibraries as $script) {
            $editmodeHeadHtml .= '<script type="text/javascript" src="' . $script . '?_dc=' . Pimcore_Version::$revision . '"></script>';
            $editmodeHeadHtml .= "\n";
        }
        // combine the pimcore scripts in non-devmode
        if ($conf->general->devmode) {
            foreach ($editmodeScripts as $script) {
                $editmodeHeadHtml .= '<script type="text/javascript" src="' . $script . '?_dc=' . Pimcore_Version::$revision . '"></script>';
                $editmodeHeadHtml .= "\n";
            }
        } else {
            $scriptContents = "";
            foreach ($editmodeScripts as $scriptUrl) {
                $scriptContents .= file_get_contents(PIMCORE_DOCUMENT_ROOT . $scriptUrl) . "\n\n\n";
            }
            $editmodeHeadHtml .= '<script type="text/javascript" src="' . Pimcore_Tool_Admin::getMinimizedScriptPath($scriptContents) . '?_dc=' . Pimcore_Version::$revision . '"></script>' . "\n";
        }
        $ns = new Zend_Session_Namespace("pimcore_admin");
        $user = User::getById($ns->user->getId());
        $lang = $user->getLanguage();
        $editmodeHeadHtml .= '<script type="text/javascript" src="/admin/misc/json-translations-system/language/' . $lang . '/?_dc=' . Pimcore_Version::$revision . '"></script>' . "\n";
        $editmodeHeadHtml .= '<script type="text/javascript" src="/admin/misc/json-translations-admin/language/' . $lang . '/?_dc=' . Pimcore_Version::$revision . '"></script>' . "\n";
        $editmodeHeadHtml .= "\n\n";
        // set var for editable configurations which is filled by Document_Tag::admin()
        $editmodeHeadHtml .= '<script type="text/javascript">
            var editableConfigurations = new Array();
            var pimcore_document_id = ' . $request->getParam("document")->getId() . ';
        </script>';
        $editmodeHeadHtml .= "\n\n<!-- /pimcore editmode -->\n\n\n";
        // add html headers for snippets in editmode, so there is no problem with javascript
        $body = $this->getResponse()->getBody();
        if ($this->controller->editmode && strpos($body, "</body>") === false && !$request->getParam("blockAutoHtml")) {
            $body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
			<html xmlns="http://www.w3.org/1999/xhtml">
			<head></head><body>' . $body . "</body></html>";
            $this->getResponse()->setBody($body);
        }
        // add scripts in html header for pages in editmode
        if ($this->controller->editmode && ($this->controller->document->getType() == "page" || $this->controller->document->getType() == "snippet")) {
            include_once "simple_html_dom.php";
            $body = $this->getResponse()->getBody();
            $html = str_get_html($body);
            if ($html) {
                if ($head = $html->find("head", 0)) {
                    $head->innertext = $head->innertext . "\n\n" . $editmodeHeadHtml;
                    $bodyElement = $html->find("body", 0);
                    $bodyElement->onunload = "pimcoreOnUnload();";
                    $bodyElement->innertext = $bodyElement->innertext . "\n\n" . '<script type="text/javascript" src="/pimcore/static/js/pimcore/document/edit/startup.js?_dc=' . Pimcore_Version::$revision . '"></script>' . "\n\n";
                    $body = $html->save();
                    $this->getResponse()->setBody($body);
                }
            }
        }
    }
 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));
 }
    $types = explode(",", $opts->getOption("types"));
}
if (in_array("document", $types)) {
    $docTypes = null;
    if ($opts->getOption("documentTypes")) {
        $docTypes = explode(",", $opts->getOption("documentTypes"));
    }
    Pimcore_Cache_Tool_Warming::documents($docTypes);
}
if (in_array("asset", $types)) {
    $assetTypes = null;
    if ($opts->getOption("assetTypes")) {
        $assetTypes = explode(",", $opts->getOption("assetTypes"));
    }
    Pimcore_Cache_Tool_Warming::assets($assetTypes);
}
if (in_array("object", $types)) {
    $objectTypes = null;
    if ($opts->getOption("objectTypes")) {
        $objectTypes = explode(",", $opts->getOption("objectTypes"));
    }
    $classes = null;
    if ($opts->getOption("classes")) {
        $classes = explode(",", $opts->getOption("classes"));
    }
    Pimcore_Cache_Tool_Warming::objects($objectTypes, $classes);
}
// disable maintenance mode if requested
if ($opts->getOption("maintenanceMode")) {
    Pimcore_Tool_Admin::deactivateMaintenanceMode();
}
Beispiel #11
0
 public function maintenanceAction()
 {
     if ($this->_getParam("activate")) {
         Pimcore_Tool_Admin::activateMaintenanceMode();
     }
     if ($this->_getParam("deactivate")) {
         Pimcore_Tool_Admin::deactivateMaintenanceMode();
     }
     $this->_helper->json(array("success" => true));
 }
Beispiel #12
0
 /**
  * This is used for user-permissions, pass a permission type (eg. list, view, save) an you know if the current user is allowed to perform the requested action
  *
  * @param string $type
  * @return boolean
  */
 public function isAllowed($type)
 {
     $currentUser = Pimcore_Tool_Admin::getCurrentUser();
     //everything is allowed for admin
     if ($currentUser->isAdmin()) {
         return true;
     }
     return $this->getResource()->isAllowed($type, $currentUser);
 }
Beispiel #13
0
 /**
  * @static
  * @return bool
  */
 public static function isInMaintenanceMode()
 {
     $file = Pimcore_Tool_Admin::getMaintenanceModeFile();
     if (is_file($file)) {
         $conf = new Zend_Config_Xml($file);
         if ($conf->sessionId) {
             return true;
         } else {
             @unlink($file);
         }
     }
     return false;
 }
Beispiel #14
0
// this includes $this->action() in templates, ...
$front = Zend_Controller_Front::getInstance();
Pimcore::initControllerFront($front);
$request = new Zend_Controller_Request_Http();
$request->setModuleName(PIMCORE_FRONTEND_MODULE);
$request->setControllerName("default");
$request->setActionName("default");
$front->setRequest($request);
$front->setResponse(new Zend_Controller_Response_Cli());
// generic pimcore setup
Pimcore::setSystemRequirements();
Pimcore::initAutoloader();
Pimcore::initConfiguration();
Pimcore::setupFramework();
Pimcore::initLogger();
Pimcore::initModules();
Pimcore::initPlugins();
//Activate Inheritance for cli-scripts
Pimcore::unsetAdminMode();
Document::setHideUnpublished(true);
Object_Abstract::setHideUnpublished(true);
Object_Abstract::setGetInheritedValues(true);
// Error reporting is enabled in CLI
@ini_set("display_errors", "On");
@ini_set("display_startup_errors", "On");
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
// skip if maintenance mode is on and the flag is not set
// we cannot use Zend_Console_Getopt here because it doesn't allow to be called twice (unrecognized parameter, ...)
if (Pimcore_Tool_Admin::isInMaintenanceMode() && (!isset($_SERVER['argv']) || !in_array("--ignore-maintenance-mode", $_SERVER['argv'])) && !stristr($_SERVER['REQUEST_URI'], '/pimcore/modules/3rdparty/adminer/index.php')) {
    die("in maintenance mode -> skip\nset the falg --ignore-maintenance-mode to force execution \n");
}
Beispiel #15
0
 public function save()
 {
     // check if there's a valid user
     if (!$this->getUser()) {
         // try to use the logged in user
         if (Pimcore::inAdmin()) {
             if ($user = Pimcore_Tool_Admin::getCurrentUser()) {
                 $this->setUser($user->getId());
             }
         }
     }
     $this->getResource()->save();
 }