themes
[ class tree: themes ] [ index: themes ] [ all elements ]

Source for file edit_css.php

Documentation is available at edit_css.php

  1. <?php
  2. /**
  3.  * @version $Header$
  4.  *
  5.  *  Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  6.  *  All Rights Reserved. See below for details and a complete list of authors.
  7.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
  8.  *
  9.  * @package themes
  10.  */
  11.  
  12. /**
  13.  * Setup
  14.  */
  15. include_once( '../kernel/setup_inc.php' );
  16. include_once( THEMES_PKG_PATH.'css_lib.php' );
  17.  
  18. /************************************
  19. **** File Management Functions
  20. ****
  21. *************************************/
  22.  
  23. function delete($dir, $pattern = "*.*")
  24. {
  25.     $deleted = false;
  26.     $pattern = str_replace(array("\*","\?"), array(".*","."), preg_quote($pattern));
  27.     if (substr($dir,-1) != "/") $dir.= "/";
  28.     if (is_dir($dir)) {
  29.         $d = opendir($dir);
  30.         while ($file = readdir($d)) {
  31.             if (is_file($dir.$file) && ereg("^".$pattern."$", $file)){
  32.                 if (unlink($dir.$file))    
  33.                     $deleted[] = $file;
  34.             }
  35.         }
  36.         closedir($d);
  37.         return $deleted;
  38.     }
  39.     else return 0;
  40. }
  41.  
  42. // it copies $wf to $wto
  43. function copy_dirs($wf, $wto)
  44. {
  45.    if (!file_exists($wto))
  46.    {
  47.        mkdir($wto, 0777);
  48.    }
  49.    $arr=ls_a($wf);
  50.    foreach ($arr as $fn)
  51.    {
  52.        if($fn)
  53.        {
  54.            $fl=$wf."/".$fn;
  55.            $flto=$wto."/".$fn;
  56.            if(is_dir($fl)) copy_dirs($fl, $flto);
  57.            else // begin 2nd improvement
  58.            {
  59.                @copy($fl, $flto);
  60.                chmod($flto, 0666);
  61.            } // end 2nd improvement
  62.        }
  63.    }
  64. }
  65.  
  66. // get an array of filesnames in the given directory
  67. function ls_a($wh)
  68. {
  69.    if ($handle = opendir($wh))
  70.    {
  71.        while (false !== ($file = readdir($handle)))
  72.        {
  73.            if ($file !== "." && $file !== ".." )
  74.            {
  75.                if(!isset($files)) $files=$file;
  76.                else $files = $file."\r\n".$files;
  77.            }
  78.        }
  79.        closedir($handle);
  80.    }
  81.    $arr=explode("\r\n", $files);
  82.    return $arr;
  83. } 
  84. /**************************************
  85. ***** End File Management Functions
  86. *****
  87. ***************************************/
  88.  
  89. $gBitSystem->verifyFeature( 'themes_edit_css' );
  90. $gBitSystem->verifyPermission( 'bit_p_create_css' );
  91.  
  92. $customCSSPath = $gBitUser->getStoragePath( NULL,$gBitUser->mUserId );    // Path to this user's storage directory
  93. $customCSSFile = $customCSSPath.'custom.css';    // Path to this user's custom stylesheet
  94. $customCSSImageURL = $gBitUser->getStorageURL( NULL,$gBitUser->mUserId ).'/images/';
  95. $gBitSmarty->assign_by_ref('customCSSImageURL',$customCSSImageURL);            
  96. // Create a custom.css for this user if they do not already have one
  97. if (!file_exists($customCSSFile)) {
  98.     if (!copy(THEMES_PKG_PATH.'/styles/basic/basic.css', $customCSSFile)) {
  99.         $gBitSmarty->assign('msg', tra("Unable to create a custom CSS file for you!"));
  100.         $gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'edit' ));
  101.         die;
  102.     }
  103. }
  104.  
  105. // Action Responses
  106. if (isset($_REQUEST["fSaveCSS"])and $_REQUEST["fSaveCSS"]) {
  107.     // Save any changes the user made to their CSS
  108.     $fp = fopen($customCSSFile, "w");
  109.  
  110.     if (!$fp) {
  111.         $gBitSmarty->assign('msg', tra("You dont have permission to write the style sheet"));
  112.         $gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'edit' ));
  113.         die;
  114.     }
  115.     
  116.     fwrite($fp, $_REQUEST["textData"]);
  117.     fclose ($fp);
  118.     $successMsg = "CSS Updated and Saved";
  119. } elseif (isset($_REQUEST["fCancelCSS"]) && $_REQUEST['fCancelCSS']) {
  120.     // Cancel (e.g. do nothing)
  121.     $successMsg = "Changes have been cancelled";
  122. } elseif (isset($_REQUEST['fResetCSS'])) {
  123.     // Reset CSS (e.g. copy an existing style as a base for their custom style)
  124.     $resetStyle = $_REQUEST['resetStyle'];
  125.     $cssData = $css_lib->load_css2_file(THEMES_PKG_PATH."styles/$resetStyle/$resetStyle.css");
  126.     if (file_exists($customCSSPath.'/images')) {
  127.         delete($customCSSPath.'/images/', '*.*');
  128.     }
  129.     if (file_exists(THEMES_PKG_PATH."styles/$resetStyle/images")) {
  130.         copy_dirs("styles/$resetStyle/images", $customCSSPath.'/images/');                
  131.     }
  132.             
  133.     $fp = fopen($customCSSFile, "w");
  134.  
  135.     if (!$fp) {
  136.         $gBitSmarty->assign('msg', tra("You dont have permission to write the style sheet"));
  137.         $gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'edit' ));
  138.         die;
  139.     }
  140.     
  141.     fwrite($fp, $cssData);
  142.     fclose ($fp);
  143.     $successMsg = "Your CSS has been reset to the $resetStyle theme.";
  144. } elseif (isset($_REQUEST['fUpload'])) {
  145.     // User has uploaded an image to use in their custom theme
  146.     //print('You uploaded: '.$_FILES['fImgUpload']['name']);
  147.     print(strtoupper($_FILES['fImgUpload']['name']));
  148.     if (!ereg(".JPG$|.PNG$|.GIF$|.BMP$",strtoupper($_FILES['fImgUpload']['name']))) {
  149.         $errorMsg = "Your image must be one of the following types: .jpg, .png, .gif, .bmp";
  150.     } else {
  151.         if ($_FILES['fImgUpload']['error'] == UPLOAD_ERR_OK && copy($_FILES['fImgUpload']['tmp_name'], $customCSSPath.'/images/'.$_FILES['fImgUpload']['name'])) {
  152.             $successMsg = $_FILES['fImgUpload']['name']." successfully added.";
  153.         }
  154.         else {
  155.             $errorMsg = "There was a problem uploading your image.";
  156.         }
  157.     }
  158. } elseif (isset($_REQUEST['fDeleteImg'])) {
  159.     // Delete one of the images in this user's storage directory
  160.     $imgName = $customCSSPath.'/images/'.$_REQUEST['fDeleteImg'];
  161.     //print("imgname: $imgName");
  162.     if (file_exists($imgName)) {
  163.         unlink($imgName);
  164.         $successMsg = $_REQUEST['fDeleteImg']." successfully deleted";
  165.     } else {
  166.         $errorMsg = $_REQUEST['fDeleteImg']." does not exists!";
  167.     }    
  168. } else {
  169.     $action = 'edit';
  170. }
  171.  
  172.  
  173. // Get the list of themes the user can choose to derive from (aka Reset to)
  174. $styles = $gBitThemes->getStyles( NULL, FALSE, FALSE );
  175. $gBitSmarty->assign_by_ref( 'styles', $styles );
  176. $assignStyle = 'basic';
  177. $gBitSmarty->assign_by_ref( 'assignStyle', $assignStyle);
  178.  
  179.  
  180. // Read in this user's custom.css to display in the textarea
  181. $lines = file($customCSSFile);
  182. $data = '';
  183. foreach ($lines as $line) {
  184.     $data .= $line;
  185. } 
  186.  
  187. $gBitSmarty->assign('data', $data);
  188. if (isset($successMsg)) 
  189.     $gBitSmarty->assign('successMsg',$successMsg);
  190. if (isset($errorMsg))
  191.     $gBitSmarty->assign('errorMsg', $errorMsg);
  192.  
  193. // Get the list of images used by this user's custom theme
  194. $imageList = ls_a($customCSSPath.'images/');
  195. $themeImages = array();
  196. foreach ($imageList as $image) {
  197.     if (ereg(".JPG$|.PNG$|.GIF$|.BMP$",strtoupper($image))) {
  198.         $themeImages[] = $image;
  199.     }
  200. }
  201.  
  202. $gBitSmarty->assign_by_ref('themeImages',$themeImages);    
  203.  
  204. $gBitSystem->display( 'bitpackage:themes/edit_css.tpl', NULL, array( 'display_mode' => 'edit' ));
  205.  
  206. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:26 +0000 by phpDocumentor 1.5.0-lsces