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

Source for file theme.php

Documentation is available at theme.php

  1. <?php
  2. /**
  3.  * user theme selection
  4.  *
  5.  * @copyright (c) 2004-15 bitweaver.org
  6.  *
  7.  * @package users
  8.  * @subpackage functions
  9.  */
  10. global $gEditMode;
  11. $gEditMode 'theme';
  12.  
  13. /**
  14.  * required setup
  15.  */
  16. include_once'../kernel/setup_inc.php' );
  17. include_onceTHEMES_PKG_PATH.'css_lib.php' );
  18. include_onceKERNEL_PKG_PATH.'BitSystem.php' );
  19.  
  20. global $gBitUser$gBitSystem;
  21.  
  22. if (!$gBitUser->isRegistered()) {
  23.     $gBitSmarty->assign('msg'tra("Permission denied: You are not logged in"));
  24.     $gBitSystem->display'error.tpl' NULLarray'display_mode' => 'display' ));
  25.     die;
  26. }
  27.  
  28. include_once(USERS_PKG_PATH.'lookup_user_inc.php');
  29.  
  30. if ($gQueryUser->mUserId != $gBitUser->mUserId && !$gBitUser->object_has_permission($gBitUser->mUserId$gQueryUser->mInfo['content_id']'bituser''p_users_admin')) {
  31.     $gBitSmarty->assign('msg'tra('You do not have permission to edit this user\'s theme'));
  32.     $gBitSystem->display('error.tpl'NULLarray'display_mode' => 'display' ));
  33.     die;
  34. }
  35.  
  36. //******* HELPER FUNCTIONS *******
  37. // get an array of filesnames in the given directory
  38. function ls_a($wh)
  39. {
  40.     $files NULL;
  41.    if (is_dir($wh&& $handle opendir($wh))
  42.    {
  43.        while (false !== ($file readdir($handle)))
  44.        {
  45.            if ($file !== "." && $file !== ".." )
  46.            {
  47.                if(!isset($files)) $files=$file;
  48.                else $files $file."\r\n".$files;
  49.            }
  50.        }
  51.        closedir($handle);
  52.    }
  53.    $arr=explode("\r\n"$files);
  54.    return $arr;
  55. }
  56.  
  57. function delete($dir$pattern "*.*")
  58. {
  59.     $deleted false;
  60.     $pattern str_replace(array("\*","\?")array(".*",".")preg_quote($pattern));
  61.     if (substr($dir,-1!= "/"$dir.= "/";
  62.     if (is_dir($dir)) {
  63.         $d opendir($dir);
  64.         while ($file readdir($d)) {
  65.             if (is_file($dir.$file&& ereg("^".$pattern."$"$file)){
  66.                 if (unlink($dir.$file))
  67.                     $deleted[$file;
  68.             }
  69.         }
  70.         closedir($d);
  71.         return $deleted;
  72.     }
  73.     else return 0;
  74. }
  75.  
  76. // it copies $wf to $wto
  77. function copy_dirs($wf$wto{
  78.     if (!file_exists($wto)) {
  79.         mkdir($wto0777);
  80.     }
  81.     $arr=ls_a($wf);
  82.     foreach ($arr as $fn{
  83.         if($fn{
  84.             $fl=$wf."/".$fn;
  85.             $flto=$wto."/".$fn;
  86.             if(is_dir($fl)) copy_dirs($fl$flto);
  87.             else // begin 2nd improvement
  88.             {
  89.                 @copy($fl$flto);
  90.                 chmod($flto0666);
  91.             // end 2nd improvement
  92.         }
  93.     }
  94. }
  95.  
  96. //******** END HELPER FUNCTIONS **********
  97.  
  98. $F array();
  99. $errorMsg   array();
  100.  
  101. // Special case: the admin has turned of custom user themes but this user currently uses his/her custom theme
  102. if ($gQueryUser->getPreference'theme' == 'custom' && !$gBitUser->canCustomizeTheme() ) {
  103.     $gQueryUser->storePreference('theme'NULL);        // Set their homepage theme to fall back to the site's themeImages
  104.     $gQueryUser->setPreference'theme'NULL );                // Update their mPrefs
  105. }
  106.  
  107. $usingCustomTheme ($gQueryUser->getPreference'theme' == 'custom' true false);
  108.  
  109. $gBitSmarty->assign_by_ref('usingCustomTheme'$usingCustomTheme);
  110.  
  111. if!$gBitUser->canCustomizeTheme() ) {
  112.     $gBitSmarty->assign('msg'tra("Feature disabled"));
  113.     $gBitSystem->display'error.tpl' NULLarray'display_mode' => 'display' ));
  114.     die;
  115. }
  116.  
  117. $customCSSPath $gQueryUser->getStoragePath('theme'$gQueryUser->mUserIdNULL);    // Path to this user's storage directory
  118.  
  119. $customCSSFile $customCSSPath.'custom.css';    // Path to this user's custom stylesheet
  120. $customCSSImageURL $gQueryUser->getStorageURL'/theme/images/'$gQueryUser->mUserId );
  121. $gBitSmarty->assign_by_ref('customCSSImageURL',$customCSSImageURL);
  122.  
  123. // Create a custom.css for this user if they do not already have one
  124. if (!file_exists($customCSSFile)) {
  125.     if (!copy(THEMES_PKG_PATH.'/styles/basic/basic.css'$customCSSFile)) {
  126.         $gBitSmarty->assign('msg'tra("Unable to create a custom CSS file for you!"));
  127.         $gBitSystem->display'error.tpl' NULLarray'display_mode' => 'display' ));
  128.         die;
  129.     }
  130. }
  131.  
  132. if (isset($_REQUEST['fUseStandardTheme']&& $_REQUEST['fUseStandardTheme']{
  133.     $gQueryUser->storePreference('theme'NULL);
  134.     $usingCustomTheme false;
  135. }
  136.  
  137. if (isset($_REQUEST['fUseCustomTheme']&& $_REQUEST['fUseCustomTheme']{
  138.     $gQueryUser->storePreference('theme''custom');
  139.     $usingCustomTheme true;
  140. }
  141.  
  142. if ($usingCustomTheme{
  143.     $assignStyle 'basic';
  144.  
  145.     // Action Responses
  146.     if (isset($_REQUEST["fSaveCSS"])and $_REQUEST["fSaveCSS"]{
  147.         // Save any changes the user made to their CSS
  148.         $fp fopen($customCSSFile"w");
  149.  
  150.         if (!$fp{
  151.             $gBitSmarty->assign('msg'tra("You dont have permission to write the style sheet"));
  152.             $gBitSystem->display'error.tpl' NULLarray'display_mode' => 'display' ));
  153.             die;
  154.         }
  155.  
  156.         fwrite($fp$_REQUEST["textData"]);
  157.         fclose ($fp);
  158.         $successMsg["CSS Updated and Saved";
  159.  
  160.     elseif (isset($_REQUEST["fCancelCSS"]&& $_REQUEST['fCancelCSS']{
  161.         // Cancel (e.g. do nothing)
  162.         $successMsg["Changes have been cancelled";
  163.  
  164.     elseif (isset($_REQUEST['fResetCSS'])) {
  165.         // Reset CSS (e.g. copy an existing style as a base for their custom style)
  166.         unlink_r$customCSSPath );
  167.         mkdir_p$customCSSPath.'/images' );
  168.         $resetStyle $_REQUEST['resetStyle'];
  169.         $cssData $csslib->load_css2_file(THEMES_PKG_PATH."styles/$resetStyle/$resetStyle.css");
  170.         if (file_exists($customCSSPath.'/images')) {
  171.             $gBitThemes->expunge_dir($customCSSPath.'/images/');
  172.         else {
  173.             mkdir_p($customCSSPath);
  174.         }
  175.  
  176.         if (file_exists(THEMES_PKG_PATH."styles/$resetStyle/images")) {
  177.             //clean out any old junk
  178.             copy_dirs(THEMES_PKG_PATH."styles/$resetStyle/images"$customCSSPath.'/images/');
  179.         }
  180.  
  181.         $fp fopen($customCSSFile"w");
  182.  
  183.         if (!$fp{
  184.             $gBitSmarty->assign('msg'tra("You dont have permission to write the style sheet"));
  185.             $gBitSystem->display'error.tpl' NULLarray'display_mode' => 'display' ));
  186.             die;
  187.         }
  188.  
  189.         fwrite($fp$cssData);
  190.         fclose ($fp);
  191.         $successMsg["Your CSS has been reset to the $resetStyle theme.";
  192.  
  193.     elseif (isset($_REQUEST['fUpload'])) {
  194.         if (!ereg(".JPG$|.PNG$|.GIF$|.BMP$",strtoupper($_FILES['fImgUpload']['name']))) {
  195.             $errorMsg["Your image must be one of the following types: .jpg, .png, .gif, .bmp";
  196.         else {
  197.             if (!file_exists($customCSSPath.'/images')) {
  198.                 mkdir_p($customCSSPath.'/images');
  199.             }
  200.             if ($_FILES['fImgUpload']['error'== UPLOAD_ERR_OK && copy($_FILES['fImgUpload']['tmp_name']$customCSSPath.'/images/'.$_FILES['fImgUpload']['name'])) {
  201.                 $successMsg[$_FILES['fImgUpload']['name']." successfully added.";
  202.             }
  203.             else {
  204.                 $errorMsg["There was a problem uploading your image.";
  205.             }
  206.         }
  207.  
  208.     elseif (isset($_REQUEST['fDeleteImg'])) {
  209.         /*$imgArray = $_REQUEST['fDeleteImg'];
  210.         foreach($imgArray as $key => $value) {
  211.             $imgPath = $customCSSPath.'/images/'.$key;
  212.             if (file_exists($imgPath)) {
  213.                 unlink($imgPath);
  214.                 $successMsg[] = "$key successfully deleted";
  215.             } else {
  216.                 $errorMsg[] = "$key does not exists!";
  217.             }
  218.         }*/
  219.         $imgName key$_REQUEST['fDeleteImg');
  220.         $imgPath $customCSSPath.'/images/'.$imgName;
  221.         if (file_exists($imgPath)) {
  222.             unlink($imgPath);
  223.             $successMsg["$imgName successfully deleted";
  224.         else {
  225.             $errorMsg["$imgName does not exists!";
  226.         }
  227.     else {
  228.         $action 'edit';
  229.     }
  230. else {
  231.     // User is selecting from the standard themes
  232.     if (isset($_REQUEST['fChangeTheme']&& $_REQUEST['fChangeTheme']{
  233.         $gQueryUser->storePreference('theme'NULL);
  234.         $successMsg["Theme successfully changed to ".$_REQUEST['fStyleChoice'];
  235.         $assignStyle $_REQUEST['fStyleChoice'];
  236.     }
  237.     header'Location: '.USERS_PKG_URL.'assigned_modules.php' );
  238. }
  239.  
  240. // Get the list of themes the user can choose to derive from (aka Reset to)
  241. $styles $gBitThemes->getStylesNULL($usingCustomTheme FALSE TRUE)FALSE );
  242. $gBitSmarty->assign_by_ref'styles'$styles );
  243.  
  244. // $assignStyle is the default style which will be selected in the drop down list
  245. if (!isset($assignStyle)) {
  246.     $assignStyle $gQueryUser->getPreference('theme''basic');
  247. }
  248. $gBitSmarty->assign_by_ref'assignStyle'$assignStyle);
  249.  
  250. // Read in this user's custom.css to display in the textarea
  251. $lines file($customCSSFile);
  252. $data '';
  253. foreach ($lines as $line{
  254.     $data .= $line;
  255. }
  256.  
  257. $gBitSmarty->assign('data'$data);
  258.  
  259. // Export success/error messages for display in the tpl.
  260. if (isset($successMsg))
  261.     $gBitSmarty->assign_by_ref('successMsg',$successMsg);
  262. if (isset($errorMsg))
  263.     $gBitSmarty->assign_by_ref('errorMsg'$errorMsg);
  264.  
  265. // Get the list of images used by this user's custom theme
  266. $imageList ls_a($customCSSPath.'images/');
  267. $themeImages array();
  268. ifcount$imageList ) ) {
  269.     foreach ($imageList as $image{
  270.         if (ereg(".JPG$|.PNG$|.GIF$|.BMP$",strtoupper($image))) {
  271.             $themeImages[$image;
  272.         }
  273.     }
  274. }
  275.  
  276. $gBitSmarty->assign('imagesCount'count($themeImages));
  277. $gBitSmarty->assign_by_ref('themeImages',$themeImages);
  278. $gBitSmarty->assign('SCRIPT_NAME'$_SERVER['SCRIPT_NAME']);
  279. $gBitSmarty->assign_by_ref('gQueryUser'$gQueryUser);
  280.  
  281. $gBitSystem->display'bitpackage:users/user_theme.tpl'NULLarray'display_mode' => 'display' ));
  282. ?>

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