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_onceTHEMES_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($wto0777);
  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($flto0666);
  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. ***** End File Management Functions
  85. *****
  86. ***************************************/
  87.  
  88. $gBitSystem->verifyFeature'themes_edit_css' );
  89. $gBitSystem->verifyPermission'bit_p_create_css' );
  90.  
  91. $customCSSPath $gBitUser->getStoragePathNULL,$gBitUser->mUserId );    // Path to this user's storage directory
  92. $customCSSFile $customCSSPath.'custom.css';    // Path to this user's custom stylesheet
  93. $customCSSImageURL $gBitUser->getStorageURLNULL,$gBitUser->mUserId ).'/images/';
  94. $gBitSmarty->assign_by_ref('customCSSImageURL',$customCSSImageURL);            
  95. // Create a custom.css for this user if they do not already have one
  96. if (!file_exists($customCSSFile)) {
  97.     if (!copy(THEMES_PKG_PATH.'/styles/basic/basic.css'$customCSSFile)) {
  98.         $gBitSmarty->assign('msg'tra("Unable to create a custom CSS file for you!"));
  99.         $gBitSystem->display'error.tpl' NULLarray'display_mode' => 'edit' ));
  100.         die;
  101.     }
  102. }
  103.  
  104. // Action Responses
  105. if (isset($_REQUEST["fSaveCSS"])and $_REQUEST["fSaveCSS"]{
  106.     // Save any changes the user made to their CSS
  107.     $fp fopen($customCSSFile"w");
  108.  
  109.     if (!$fp{
  110.         $gBitSmarty->assign('msg'tra("You dont have permission to write the style sheet"));
  111.         $gBitSystem->display'error.tpl' NULLarray'display_mode' => 'edit' ));
  112.         die;
  113.     }
  114.     
  115.     fwrite($fp$_REQUEST["textData"]);
  116.     fclose ($fp);
  117.     $successMsg "CSS Updated and Saved";
  118. elseif (isset($_REQUEST["fCancelCSS"]&& $_REQUEST['fCancelCSS']{
  119.     // Cancel (e.g. do nothing)
  120.     $successMsg "Changes have been cancelled";
  121. elseif (isset($_REQUEST['fResetCSS'])) {
  122.     // Reset CSS (e.g. copy an existing style as a base for their custom style)
  123.     $resetStyle $_REQUEST['resetStyle'];
  124.     $cssData $css_lib->load_css2_file(THEMES_PKG_PATH."styles/$resetStyle/$resetStyle.css");
  125.     if (file_exists($customCSSPath.'/images')) {
  126.         delete($customCSSPath.'/images/''*.*');
  127.     }
  128.     if (file_exists(THEMES_PKG_PATH."styles/$resetStyle/images")) {
  129.         copy_dirs("styles/$resetStyle/images"$customCSSPath.'/images/');                
  130.     }
  131.             
  132.     $fp fopen($customCSSFile"w");
  133.  
  134.     if (!$fp{
  135.         $gBitSmarty->assign('msg'tra("You dont have permission to write the style sheet"));
  136.         $gBitSystem->display'error.tpl' NULLarray'display_mode' => 'edit' ));
  137.         die;
  138.     }
  139.     
  140.     fwrite($fp$cssData);
  141.     fclose ($fp);
  142.     $successMsg "Your CSS has been reset to the $resetStyle theme.";
  143. elseif (isset($_REQUEST['fUpload'])) {
  144.     // User has uploaded an image to use in their custom theme
  145.     //print('You uploaded: '.$_FILES['fImgUpload']['name']);
  146.     print(strtoupper($_FILES['fImgUpload']['name']));
  147.     if (!ereg(".JPG$|.PNG$|.GIF$|.BMP$",strtoupper($_FILES['fImgUpload']['name']))) {
  148.         $errorMsg "Your image must be one of the following types: .jpg, .png, .gif, .bmp";
  149.     else {
  150.         if ($_FILES['fImgUpload']['error'== UPLOAD_ERR_OK && copy($_FILES['fImgUpload']['tmp_name']$customCSSPath.'/images/'.$_FILES['fImgUpload']['name'])) {
  151.             $successMsg $_FILES['fImgUpload']['name']." successfully added.";
  152.         }
  153.         else {
  154.             $errorMsg "There was a problem uploading your image.";
  155.         }
  156.     }
  157. elseif (isset($_REQUEST['fDeleteImg'])) {
  158.     // Delete one of the images in this user's storage directory
  159.     $imgName $customCSSPath.'/images/'.$_REQUEST['fDeleteImg'];
  160.     //print("imgname: $imgName");
  161.     if (file_exists($imgName)) {
  162.         unlink($imgName);
  163.         $successMsg $_REQUEST['fDeleteImg']." successfully deleted";
  164.     else {
  165.         $errorMsg $_REQUEST['fDeleteImg']." does not exists!";
  166.     }    
  167. else {
  168.     $action 'edit';
  169. }
  170.  
  171.  
  172. // Get the list of themes the user can choose to derive from (aka Reset to)
  173. $styles $gBitThemes->getStylesNULLFALSEFALSE );
  174. $gBitSmarty->assign_by_ref'styles'$styles );
  175. $assignStyle 'basic';
  176. $gBitSmarty->assign_by_ref'assignStyle'$assignStyle);
  177.  
  178.  
  179. // Read in this user's custom.css to display in the textarea
  180. $lines file($customCSSFile);
  181. $data '';
  182. foreach ($lines as $line{
  183.     $data .= $line;
  184.  
  185. $gBitSmarty->assign('data'$data);
  186. if (isset($successMsg)) 
  187.     $gBitSmarty->assign('successMsg',$successMsg);
  188. if (isset($errorMsg))
  189.     $gBitSmarty->assign('errorMsg'$errorMsg);
  190.  
  191. // Get the list of images used by this user's custom theme
  192. $imageList ls_a($customCSSPath.'images/');
  193. $themeImages array();
  194. foreach ($imageList as $image{
  195.     if (ereg(".JPG$|.PNG$|.GIF$|.BMP$",strtoupper($image))) {
  196.         $themeImages[$image;
  197.     }
  198. }
  199.  
  200. $gBitSmarty->assign_by_ref('themeImages',$themeImages);    
  201.  
  202. $gBitSystem->display'bitpackage:themes/edit_css.tpl'NULLarray'display_mode' => 'edit' ));
  203.  
  204. ?>

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