public function chooseTheme() { $language = OW::getLanguage(); $router = OW::getRouter(); $this->themeService->updateThemeList(); $this->themeService->updateThemesInfo(); $themes = $this->themeService->findAllThemes(); $themesInfo = array(); $activeTheme = OW::getThemeManager()->getSelectedTheme()->getDto()->getKey(); /* @var $theme BOL_Theme */ foreach ($themes as $theme) { $themesInfo[$theme->getKey()] = array("key" => $theme->getKey(), "title" => $theme->getTitle(), "iconUrl" => $this->themeService->getStaticUrl($theme->getKey()) . BOL_ThemeService::ICON_FILE, "previewUrl" => $this->themeService->getStaticUrl($theme->getKey()) . BOL_ThemeService::PREVIEW_FILE, "active" => $theme->getKey() == $activeTheme, "changeUrl" => $router->urlFor(__CLASS__, "changeTheme", array(BOL_StorageService::URI_VAR_KEY => $theme->getKey())), "update_url" => (int) $theme->getUpdate() == 1 ? $router->urlFor("ADMIN_CTRL_Themes", "updateRequest", array(BOL_StorageService::URI_VAR_KEY => $theme->getKey())) : false); if (!in_array($theme->getKey(), array(BOL_ThemeService::DEFAULT_THEME, $activeTheme))) { $themesInfo[$theme->getKey()]["delete_url"] = $router->urlFor(__CLASS__, "deleteTheme", array("key" => $theme->getKey())); } if ($theme->getLicenseCheckTimestamp() > 0) { $params = array(BOL_StorageService::URI_VAR_BACK_URI => urlencode($router->uriForRoute("admin_themes_choose")), BOL_StorageService::URI_VAR_KEY => $theme->getKey(), BOL_StorageService::URI_VAR_ITEM_TYPE => BOL_StorageService::URI_VAR_ITEM_TYPE_VAL_THEME, BOL_StorageService::URI_VAR_DEV_KEY => $theme->getDeveloperKey(), BOL_StorageService::URI_VAR_RETURN_RESULT => 0); $themesInfo[$theme->getKey()]["license_url"] = OW::getRequest()->buildUrlQueryString($router->urlFor("ADMIN_CTRL_Storage", "checkItemLicense"), $params); } $xmlInfo = $this->themeService->getThemeXmlInfoForKey($theme->getKey()); $themesInfo[$theme->getKey()] = array_merge($themesInfo[$theme->getKey()], $xmlInfo); } OW::getDocument()->addScript(OW::getPluginManager()->getPlugin("admin")->getStaticJsUrl() . "theme_select.js"); OW::getDocument()->addScript(OW::getPluginManager()->getPlugin("base")->getStaticJsUrl() . "jquery.sticky.js"); $addData = array("deleteConfirmMsg" => $language->text("admin", "themes_choose_delete_confirm_msg"), "deleteActiveThemeMsg" => $language->text("admin", "themes_cant_delete_active_theme")); OW::getDocument()->addOnloadScript("window.owThemes = new ThemesSelect(" . json_encode($themesInfo) . ", " . json_encode($addData) . ");\n \t\$('.selected_theme_info input.theme_select_submit').click(function(){\n \t\t\twindow.location.href = '{$themesInfo[$activeTheme]['changeUrl']}';\n \t\t});\n \$('.selected_theme_info_stick').sticky({topSpacing:60});\n \$('.admin_themes_select a.theme_icon').click( function(){ \$('.theme_info .theme_control_button').hide(); });"); $this->assign("adminThemes", array(BOL_ThemeService::DEFAULT_THEME => $themesInfo[BOL_ThemeService::DEFAULT_THEME])); $this->assign("themeInfo", $themesInfo[$activeTheme]); $event = new OW_Event("admin.filter_themes_to_choose", array(), $themesInfo); OW::getEventManager()->trigger($event); $this->assign("themes", $event->getData()); // add theme $form = new Form("theme-add"); $form->setEnctype(Form::ENCTYPE_MULTYPART_FORMDATA); $file = new FileField("file"); $form->addElement($file); $submit = new Submit("submit"); $submit->setValue($language->text("admin", "plugins_manage_add_submit_label")); $form->addElement($submit); $this->addForm($form); if (OW::getRequest()->isPost()) { if ($form->isValid($_POST)) { $data = $form->getValues(); $result = UTIL_File::checkUploadedFile($_FILES["file"]); if (!$result["result"]) { $this->feedback->error($result["message"]); $this->redirect($router->urlForRoute("admin_themes_choose")); } $pluginfilesDir = OW::getPluginManager()->getPlugin("base")->getPluginFilesDir(); $tempFile = $this->getTemDirPath() . UTIL_String::getRandomStringWithPrefix("theme_add") . ".zip"; $tempDirName = UTIL_String::getRandomStringWithPrefix("theme_add"); if (!move_uploaded_file($_FILES["file"]["tmp_name"], $tempFile)) { $this->feedback->error($language->text("admin", "manage_theme_add_move_file_error")); $this->redirect($router->urlForRoute("admin_themes_choose")); } $zip = new ZipArchive(); if ($zip->open($tempFile) === true) { $zip->extractTo($this->getTemDirPath() . $tempDirName); $zip->close(); } else { $this->feedback->error($language->text("admin", "manage_theme_add_extract_error")); $this->redirect($router->urlForRoute("admin_themes_choose")); } unlink($tempFile); $this->redirect(OW::getRequest()->buildUrlQueryString($router->urlFor(__CLASS__, "processAdd"), array("dir" => $tempDirName))); } } }
/** * * @param string $fileArr * @return \BOL_ThemeImage */ public function addImage($fileArr) { $result = UTIL_File::checkUploadedFile($fileArr, self::CONTROL_IMAGE_MAX_FILE_SIZE_IN_MB * 1024 * 1024); if (!$result["result"]) { return null; } if (!UTIL_File::validateImage($fileArr["name"])) { return null; } $image = new BOL_ThemeImage(); $image->addDatetime = time(); $this->themeImageDao->save($image); $ext = UTIL_File::getExtension($fileArr["name"]); $imageName = "theme_image_" . $image->getId() . "." . $ext; //cloudfiles header fix for amazon : need right extension to upload file with right header $newTempName = $fileArr["tmp_name"] . "." . $ext; rename($fileArr['tmp_name'], $newTempName); OW::getStorage()->copyFile($newTempName, $this->getUserfileImagesDir() . $imageName); if (file_exists($newTempName)) { unlink($newTempName); } $image->setFilename($imageName); $this->themeImageDao->save($image); return $image; }
/** * Uploads new plugin and extracts archive contecnts. */ public function add() { OW::getNavigation()->activateMenuItem(OW_Navigation::ADMIN_PLUGINS, "admin", "sidebar_menu_plugins_add"); $language = OW::getLanguage(); $feedback = OW::getFeedback(); $form = new Form("plugin-add"); $form->setEnctype(Form::ENCTYPE_MULTYPART_FORMDATA); $file = new FileField("file"); $form->addElement($file); $submit = new Submit("submit"); $submit->setValue($language->text("admin", "plugins_manage_add_submit_label")); $form->addElement($submit); $this->addForm($form); if (OW::getRequest()->isPost()) { if ($form->isValid($_POST)) { $data = $form->getValues(); $result = UTIL_File::checkUploadedFile($_FILES["file"]); if (!$result["result"]) { $feedback->error($result["message"]); $this->redirect(); } $pluginfilesDir = OW::getPluginManager()->getPlugin("base")->getPluginFilesDir(); $tempFile = $pluginfilesDir . UTIL_String::getRandomStringWithPrefix("plugin_add") . ".zip"; $tempDirName = UTIL_String::getRandomStringWithPrefix("plugin_add"); if (!move_uploaded_file($_FILES["file"]["tmp_name"], $tempFile)) { $feedback->error($language->text("admin", "manage_plugin_add_move_file_error")); $this->redirectToAction("index"); } $zip = new ZipArchive(); if ($zip->open($tempFile) === true) { $zip->extractTo($this->getTemDirPath() . $tempDirName); $zip->close(); } else { $feedback->error($language->text("admin", "manage_plugin_add_extract_error")); $this->redirectToAction("index"); } unlink($tempFile); $this->redirect(OW::getRequest()->buildUrlQueryString(OW::getRouter()->urlFor(__CLASS__, "processAdd"), array("dir" => $tempDirName))); } } }