Pixelpost Forum

Pixelpost Forum (http://www.pixelpost.org/forum/index.php)
-   Hacks and Modifications (http://www.pixelpost.org/forum/forumdisplay.php?f=16)
-   -   install script (http://www.pixelpost.org/forum/showthread.php?t=2767)

eon 11-30-2005 10:26 AM

install script
 
I'm working on a script to install parts of new code in an existing code. I call it an install script.

Code:

<?php
function update_file($filename, $search, $replacement, $rowinfo){
        // Let's make sure the file exists and is writable first.
        if (is_writable($filename)) {
       
                // In our example we're opening $filename in append mode.
                // The file pointer is at the bottom of the file hence
                // that's where $somecontent will go when we fwrite() it.
                if (!$handle = fopen($filename, "r+")) {
                        $warning .= "Cannot open file ($filename).<br />";
                        exit;
                }
       
                // Read the content out the file
                $contents = fread($handle, filesize($filename));
               
                // Replace the content with the new content
                $newcontent = str_replace(stripslashes($search),stripslashes($replacement),$contents);
               
                // Rewind the position of a file pointer. Otherwise the new text wil be placed behind the old text
                rewind($handle);
               
                // Write $somecontent to our opened file.
                if (fwrite($handle, $newcontent) === FALSE) {
                        $warning .= "Cannot write to file ($filename).<br />";
                        exit;
                }
               
                // Flushes the output to a file, function? I don't know.
                fflush($handle);
                $warning .= "Success, update file ($filename, $rowinfo).<br />";
               
                // Truncates a file to a given length.
                ftruncate($handle, ftell($handle));
               
                // Close file
                fclose($handle);
       
        }else{
                $warning .= "The file $filename is not writable.<br />";
        }
        return $warning;
}

//edit file
$file = "file.php";

//the rownumbers can be different
$rowinfo = '106 (remove row), information about the line';
$search = 'addslashes($code) to replace';
$replacement = 'addsclashes($code)';
echo update_file($file,$search,$replacement,$rowinfo);
?>

But it is not working very well. When the program have to search a code with multiple lines it can't find it', so it won't replace the code.

Does anyone know a solotion, or have made already an install code?

tinyblob 11-30-2005 10:40 AM

What's the benefit to this, in relation to Pixelpost?

I'm personally against self-modifying code and the like. I don't believe my server is as good a programmer as i am ;)

eon 11-30-2005 11:01 AM

I made a hack on several lines in serveral files. For people who don't want or can't edit there files I want to make a install script. Not everyone knows php.

Of course for the people who like to hack I write a howto or they can read my code.

tinyblob 11-30-2005 11:04 AM

The problem face there is that the people who are willing to install a hack, probably have done so already.

So if they've already hacked their file, your hack installer may not work.

By the way, the addon system is exceptionally powerful, i'm yet to find anything that actually requires a hack. What is it your hack does?

eon 11-30-2005 11:15 AM

Instand of pictures you can use just text. Then you can make a thumbnail of the text. You can use this text as an introduction of a serie photo's, for example.

http://tweakers.net/ext/f/11b26ba65b...cd318/full.jpg

raminia 11-30-2005 11:59 AM

cool

tinyblob 11-30-2005 12:01 PM

Ah yes. I'm working on something similar for the "Projects" version of my website.

eon 11-30-2005 03:35 PM

You can have my source code. No problem.

But how do you distribute large or complex hacks? Just make your own pixelpost is not the solution, and everytime writing a description how to hack is also not the solution.

tinyblob 11-30-2005 03:38 PM

In my opinion?

Only write addons, if you can't accomplish something that way, and you need to create a hack, it's probably too complex for public release.

eon 11-30-2005 03:47 PM

The problem is that pixelpost is not flexible enough. You can use pixelpost only for images. Wouldn't it be nice that you can use pixelpost also for text, video, audio? By just writing an addon for it.

I love Pixelpost for it's structure. But some code in the is not flexible. Take for example the menu of the administrator. That's a static menu.

If you want a can send you de code and you can see by your self if the code is complex. I don't think so.


All times are GMT. The time now is 05:50 AM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.