Welcome Guest, Not a member yet? Register   Sign In
[Solved] Website generator
#1

[eluser]Jareish[/eluser]
Hi all,

I'm building a CMS to create websites. Everything works fine, people can input stuff, it comes in the database and I've written the template file to be filled in.

After pressing the "create a zip" button, my builder function starts to run. It basicly pulls a template file (for instance index.html.php) fills in the $data and stores a static html file in a zip.

Code:
$this->zip->add_data('index.html', $this->parse_html('build/html/index.html.php', $data));

    function parse_html($file, $data)
    {
        ob_start();    
        $this->load->view($file, $data);
        $datasource = ob_get_contents();
        ob_end_clean();
        return $datasource;
    }

Now this is where I start having problems.

1) This doesn't really seem a clean method (I have to generate 20 files like this)
2) I alsoo need to copy images and javascript to the zip, these ofcourse don't need to be parsed as a view, but can be copied straight into a zip in a specific directory. How would I do this?

if I use $this->zip->read_file() the file either goes in the root (while I want images in a /images folder) or if oyu pass TRUE, it uses the directory in which the image resides, in this case base_url().'template/images'

So I thought about reading the datastream of that image using file_get_contents and use add_data() so I can specify the output directory. But even though I have fopen and curl enabled on my server, I get a stream error. I tried absolute pathing, relative, inside the view, inside the controller, outside the application, google.com etc file_get_contents/curl/fopen nothing works, all stream errors. IMO a stream error is something you get when he can find the file but isn't allowed to read, so either CI blocks it, or something else fishy is going on, on my server.

my curl function:
Code:
function curl_get_file($filename)
    {
        $ch = curl_init();
        $timeout = 5; // set to zero for no timeout
        curl_setopt ($ch, CURLOPT_URL, $filename);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $file_contents = curl_exec($ch);
        curl_close($ch);

        // display file
        return $file_contents;
    }

my file_get_contents function
Code:
function getFile($filename)
    {
        ob_start();    
        file_get_contents($filename);
        $datasource = ob_get_contents();
        ob_end_clean();
        return $datasource;
    }
(not sure if I need the ob_start here).

In short, my question would be, could my html file parser be cleaner (opening views over and over doesn't really seem clean).

And second question, how can I copy images/javascript/flash to the zip while maintaining a specific directory structure.

PS: My goal is to create a html template where I fill in the blanks with php, then output a html with no php in it, so the user can run it locally and on non php servers.


Messages In This Thread
[Solved] Website generator - by El Forum - 11-25-2010, 03:14 AM
[Solved] Website generator - by El Forum - 11-25-2010, 03:25 AM
[Solved] Website generator - by El Forum - 11-25-2010, 03:52 AM
[Solved] Website generator - by El Forum - 11-25-2010, 03:59 AM
[Solved] Website generator - by El Forum - 11-25-2010, 04:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB