Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    made a widget to change the web configurator theme

    Development
    1
    1
    402
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Cloudless Smart HomeC
      Cloudless Smart Home
      last edited by

      It looks a little clunky, but doesn't throw any errors and works as expected. Would someone that understands the code better than me mind helping me clean it up, and let me know if they see any problems?

      change_theme.widget.php

      <?php
      
      require_once("guiconfig.inc");
      
      $pconfig['webguicss'] = $config['system']['webgui']['webguicss'];
      
      $changedesc = gettext("System") . ": ";
      $changecount = 0;
      
      if ($_POST) {
      
      	$changecount++;
      
      	unset($input_errors);
      	$pconfig = $_POST;
      
      
      	validate_webguicss_field($input_errors, $_POST['webguicss']);
      
      
      		if ($_POST['webguicss']) {
      			$config['system']['webgui']['webguicss'] = $_POST['webguicss'];
      		} else {
      			unset($config['system']['webgui']['webguicss']);
      		}
      		
      		if ($changecount > 0) {
      			write_config($changedesc);
      		}
      
      		$changes_applied = true;
      
      		// Reload the filter - plugins might need to be run.
      		$retval |= filter_configure();
      	}
      
      
      
      if ($input_errors) {
      	print_input_errors($input_errors);
      }
      
      if ($changes_applied) {
      	print_apply_result_box($retval);
      }
      ?>
      <div id="container">
      <?php
      
      $form = new Form;
      
      
      $section = new Form_Section(' ');
      
      
      gen_webguicss_field($section, $pconfig['webguicss']);
      
      
      $form->add($section);
      
      print $form;
      
      $csswarning = sprintf(gettext("%sUser-created themes are unsupported, use at your own risk."), "<br />");
      
      ?>
      </div>
      
      <script type="text/javascript">
      //<![CDATA[
      events.push(function() {
      
      	function setThemeWarning() {
      		if ($('#webguicss').val().startsWith("pfSense")) {
      			$('#csstxt').html("").addClass("text-default");
      		} else {
      			$('#csstxt').html("<?=$csswarning?>").addClass("text-danger");
      		}
      	}
      
      	$('#webguicss').change(function() {
      		setThemeWarning();
      	});
      
      	setThemeWarning();
      
      	// Suppress "Delete row" button if there are fewer than two rows
      	checkLastRow();
      });
      //]]>
      </script>
      
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.