Source for file edit_css.php
Documentation is available at edit_css.php
* Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
* All Rights Reserved. See below for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
include_once( '../kernel/setup_inc.php' );
include_once( THEMES_PKG_PATH. 'css_lib.php' );
/************************************
**** File Management Functions
*************************************/
function delete($dir, $pattern = "*.*")
if (substr($dir,- 1) != "/") $dir.= "/";
if (is_file($dir. $file) && ereg("^". $pattern. "$", $file)){
else // begin 2nd improvement
// get an array of filesnames in the given directory
while (false !== ($file = readdir($handle)))
if ($file !== "." && $file !== ".." )
if(!isset ($files)) $files= $file;
else $files = $file. "\r\n". $files;
/**************************************
***** End File Management Functions
***************************************/
$gBitSystem->verifyFeature( 'themes_edit_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( NULL,$gBitUser->mUserId ). '/images/';
$gBitSmarty->assign_by_ref('customCSSImageURL',$customCSSImageURL);
// Create a custom.css for this user if they do not already have one
$gBitSmarty->assign('msg', tra("Unable to create a custom CSS file for you!"));
$gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'edit' ));
if (isset ($_REQUEST["fSaveCSS"])and $_REQUEST["fSaveCSS"]) {
// Save any changes the user made to their CSS
$fp = fopen($customCSSFile, "w");
$gBitSmarty->assign('msg', tra("You dont have permission to write the style sheet"));
$gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'edit' ));
fwrite($fp, $_REQUEST["textData"]);
$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");
delete($customCSSPath. '/images/', '*.*');
copy_dirs("styles/$resetStyle/images", $customCSSPath. '/images/');
$fp = fopen($customCSSFile, "w");
$gBitSmarty->assign('msg', tra("You dont have permission to write the style sheet"));
$gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'edit' ));
$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']);
if (!ereg(".JPG$|.PNG$|.GIF$|.BMP$",strtoupper($_FILES['fImgUpload']['name']))) {
$errorMsg = "Your image must be one of the following types: .jpg, .png, .gif, .bmp";
if ($_FILES['fImgUpload']['error'] == UPLOAD_ERR_OK && copy($_FILES['fImgUpload']['tmp_name'], $customCSSPath. '/images/'. $_FILES['fImgUpload']['name'])) {
$successMsg = $_FILES['fImgUpload']['name']. " successfully added.";
$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");
$successMsg = $_REQUEST['fDeleteImg']. " successfully deleted";
$errorMsg = $_REQUEST['fDeleteImg']. " does not exists!";
// Get the list of themes the user can choose to derive from (aka Reset to)
$styles = $gBitThemes->getStyles( NULL, FALSE, FALSE );
$gBitSmarty->assign_by_ref( 'styles', $styles );
$gBitSmarty->assign_by_ref( 'assignStyle', $assignStyle);
// Read in this user's custom.css to display in the textarea
$lines = file($customCSSFile);
foreach ($lines as $line) {
$gBitSmarty->assign('data', $data);
$gBitSmarty->assign('successMsg',$successMsg);
$gBitSmarty->assign('errorMsg', $errorMsg);
// Get the list of images used by this user's custom theme
$imageList = ls_a($customCSSPath. 'images/');
foreach ($imageList as $image) {
$gBitSmarty->assign_by_ref('themeImages',$themeImages);
$gBitSystem->display( 'bitpackage:themes/edit_css.tpl', NULL, array( 'display_mode' => 'edit' ));
|