Save css code by admin

Asked

Viewed 130 times

1

I have a PHP function that will show me all the CSS code on front end before HTML. Only the admin can see this CSS code printed on the screen, through the method "include".

What I’m trying to figure out is how to copy all this CSS displayed on the screen to a new CSS file.

Taking into account that this Cssque file appears on the screen it contains PHP variables, but on the screen it does not show these variables, but the value of them printed (colors, font size, etc)... or the output code presented by browser.

What I want to avoid is that the admin has to copy all this CSS manually through the screen, and have to paste it into a new CSS file.

So now, I don’t know how to copy this CSS that is on the screen with some specific function for this, either PHP or Javascript. There are about 2000 lines to be copied to a new CSS file.

Can someone give me some light on how I can get this? Since the intended is not a function to copy contents from one file to another, with the method copy, in this case all the PHP code inside the CSS would be copied. What I intend is a way to copy the output code presented by browser already with all CSS values (colors, font sizes, etc).

  • Copying the result to the clipboard helps?

  • 1

    This question seems to me to be formulated with a lot of information that is not part of the problem, if I understand correctly. If I’m not mistaken, your question is actually "how do I save the contents of a variable in a file", fix me if I’m wrong.

  • I think he wants to take what’s on the screen, the css with the values of the php variables.

1 answer

0

I think you could do more or less the following:

<?php

    $conteudoProcessado = '* { padding: 0; }';

?>

<form action="salvarArquivo.php" method="post">
    <input type="hidden" name="conteudoProcessado" value="<?php echo $conteudoProcessado; ?>" />

    <div>
        <?php echo $conteudoProcessado; ?>
    </div>

    <buttom type="submit"> Salvar </button>
</form>

And there in your file salvarArquivo.php you make the saving logic of a file with the contents of the variable $_POST['conteudoProcessado'] and if you wish you can return the saved file to the user.

If you want the user to be able to change the generated css you can use a textarea instead of a input hidden and remove the div with the contents of the file.

  • The problem is how I will store the CSS code that is printed on the screen for this "$contentProcessed" variable. Even if I get this, I have no idea how to copy this variable content into another file, for example: style.css

  • You generate this dynamically correct CSS?

  • Yes via admin with custom.css filename

  • How do you view file content for admin user?

  • it has the color panel with jscolor.js and chooses the colors you want for each html tag on a specific page in the administrative part of the site.

  • for him to see the result, in <head> I have the function call in this way that allows to see all the CSS before the HTML:

  • <link rel="Alternate stylesheet" type="text/css" title="custom" href="<? php echo nointernal_css() ?>

  • If it chooses the colors, you can put these fields inside a form and have the form Submit you create the file with the settings set by the user

  • Try to change your question so that it becomes clearer the way you are doing it, because if it will not be difficult to help you

  • the form exists, otherwise it would not be possible to submit the modifications by the admin user. I don’t know how I can edit the initial question in a simple way.

  • So what if it was a method for copying the source code, but only the CSS, would you then have a solution? Maybe to a clipboard as you mentioned, give a Submit and replace the file style.css. Do you have any functional examples you can put here? Thank you for your help.

  • There are ways you can put some of the code you use to generate the css with the options selected by the user?

  • I managed to resolve, thank you for your intervention :)

  • if (isset($_POST['outcss'])) {&#xA; $outcss = $_POST['outcss'];&#xA; $stylecss = fopen('directorio','w');&#xA; fwrite($stylecss, $outcss);&#xA; fclose($stylecss);&#xA;}&#xA; <form method="post">&#xA; <textarea name="outcss" readonly="readonly">&#xA; <? php echo nointernal_css() ? > </textarea> <button>save file</button> </form>

Show 9 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.