verifyFeature( 'themes_edit_css' ); $gBitSystem->verifyPermission( 'bit_p_create_css' ); $customCSSPath = $gBitUser->getStoragePath( null,$gBitUser->mUserId ); // Path to this user's storage directory $customCSSFile = $customCSSPath.'custom.css'; // Path to this user's custom stylesheet $customCSSImageURL = $gBitUser->getStorageURL( $gBitUser->mUserId ).'/images/'; $gBitSmarty->assign('customCSSImageURL',$customCSSImageURL); // Create a custom.css for this user if they do not already have one if (!file_exists($customCSSFile)) { if (!copy(THEMES_PKG_PATH.'/styles/basic/basic.css', $customCSSFile)) { $gBitSmarty->assign('msg', KernelTools::tra("Unable to create a custom CSS file for you!")); $gBitSystem->display( 'error.tpl' , null, [ 'display_mode' => 'edit' ]); die; } } // Action Responses if (isset($_REQUEST["fSaveCSS"])and $_REQUEST["fSaveCSS"]) { // Save any changes the user made to their CSS $fp = fopen($customCSSFile, "w"); if (!$fp) { $gBitSmarty->assign('msg', KernelTools::tra ("You dont have permission to write the style sheet")); $gBitSystem->display( 'error.tpl' , null, [ 'display_mode' => 'edit' ]); die; } fwrite($fp, $_REQUEST["textData"]); fclose ($fp); $successMsg = "CSS Updated and Saved"; } elseif (isset($_REQUEST["fCancelCSS"]) && $_REQUEST['fCancelCSS']) { // Cancel (e.g. do nothing) $successMsg = "Changes have been cancelled"; } elseif (isset($_REQUEST['fResetCSS'])) { // Reset CSS (e.g. copy an existing style as a base for their custom style) $resetStyle = $_REQUEST['resetStyle']; $cssData = $css_lib->load_css2_file(THEMES_PKG_PATH."styles/$resetStyle/$resetStyle.css"); if (file_exists($customCSSPath.'/images')) { delete($customCSSPath.'/images/', '*.*'); } if (file_exists(THEMES_PKG_PATH."styles/$resetStyle/images")) { copy_dirs("styles/$resetStyle/images", $customCSSPath.'/images/'); } $fp = fopen($customCSSFile, "w"); if (!$fp) { $gBitSmarty->assign('msg', KernelTools::tra("You dont have permission to write the style sheet")); $gBitSystem->display( 'error.tpl' , null, [ 'display_mode' => 'edit' ]); die; } fwrite($fp, $cssData); fclose ($fp); $successMsg = "Your CSS has been reset to the $resetStyle theme."; } elseif (isset($_REQUEST['fUpload'])) { // User has uploaded an image to use in their custom theme //print('You uploaded: '.$_FILES['fImgUpload']['name']); print(strtoupper($_FILES['fImgUpload']['name'])); if (!preg_match("/.JPG$|.PNG$|.GIF$|.BMP$/",strtoupper($_FILES['fImgUpload']['name']))) { $errorMsg = "Your image must be one of the following types: .jpg, .png, .gif, .bmp"; } else { if ($_FILES['fImgUpload']['error'] == UPLOAD_ERR_OK && copy($_FILES['fImgUpload']['tmp_name'], $customCSSPath.'/images/'.$_FILES['fImgUpload']['name'])) { $successMsg = $_FILES['fImgUpload']['name']." successfully added."; } else { $errorMsg = "There was a problem uploading your image."; } } } elseif (isset($_REQUEST['fDeleteImg'])) { // Delete one of the images in this user's storage directory $imgName = "$customCSSPath/images/".$_REQUEST['fDeleteImg']; //print("imgname: $imgName"); if (file_exists($imgName)) { unlink($imgName); $successMsg = $_REQUEST['fDeleteImg']." successfully deleted"; } else { $errorMsg = $_REQUEST['fDeleteImg']." does not exists!"; } } else { $action = 'edit'; } // Get the list of themes the user can choose to derive from (aka Reset to) $styles = $gBitThemes->getStyles( null, false, false ); $gBitSmarty->assign( 'styles', $styles ); $assignStyle = 'basic'; $gBitSmarty->assign( 'assignStyle', $assignStyle); // Read in this user's custom.css to display in the textarea $lines = file($customCSSFile); $data = ''; foreach ($lines as $line) { $data .= $line; } $gBitSmarty->assign('data', $data); if (isset($successMsg)) $gBitSmarty->assign('successMsg',$successMsg); if (isset($errorMsg)) $gBitSmarty->assign('errorMsg', $errorMsg); // Get the list of images used by this user's custom theme $imageList = ls_a($customCSSPath.'images/'); $themeImages = []; foreach ($imageList as $image) { if (preg_match("/.JPG$|.PNG$|.GIF$|.BMP$/",strtoupper($image))) { $themeImages[] = $image; } } $gBitSmarty->assign('themeImages',$themeImages); $gBitSystem->display( 'bitpackage:themes/edit_css.tpl', null, [ 'display_mode' => 'edit' ]);