PDA

View Full Version : install script


eon
11-30-2005, 10:26 AM
I'm working on a script to install parts of new code in an existing code. I call it an install script.

<?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($re placement),$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/11b26ba65b5a2a30f2edae66be4cd318/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.

Joe[y]
11-30-2005, 03:50 PM
in 1.5 the addons system allows users to write addons that they can place anywhere around the admin panel - soon i don't think there will be any limitations AT ALL with pixelpost addons.

tinyblob
11-30-2005, 03:53 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.
But pixelpost IS a photoblogging software.
If we make it too flexible it will lose focus.

eon
11-30-2005, 05:50 PM
But pixelpost IS a photoblogging software.
If we make it too flexible it will lose focus.

It's true, Pixelpost is a photoblog. But when I went go true the code to write my hack I saw that it was very easy to use pixelpost for more than pictures only.

For example, I use only one extra field (type) in the table pixelpost to show Pixelpost the differents between a picture and a text. With this field Pixelpost decides with template it has to use (picture_template.php or text_template.php). It was very easy to make and it will be very easy to build pixelpost to something more than a photoblog.

But I know it is easy to say of me. I'm not working on pixelpost for a long time. ;) Respect for the people who build Pixelpost.

raminia
11-30-2005, 08:35 PM
Once I was trying to do some install script for PP in dev section but I realized that to make it work people should give chmod to some directory and it become complicated for many people that we presume the install script will help them.

I assume the install script would not ease the install but makes it more professional and fancy.

raminia
11-30-2005, 08:43 PM
For example, I use only one extra field (type) in the table pixelpost to show Pixelpost the differents between a picture and a text. With this field Pixelpost decides with template it has to use (picture_template.php or text_template.php). It was very easy to make and it will be very easy to build pixelpost to something more than a photoblog.

But I know it is easy to say of me. I'm not working on pixelpost for a long time. ;) Respect for the people who build Pixelpost.

Yeah it's easy to expand PP capabilities but it's not easy to support that extended child. We can hope that some one fork PP and introduces a new universal blogging system BUT, a big but ;), keeping the simplicity is the key to success for pixelpost. This tiny program with flexible photoblogging features cannot compete with those giant cms softwares with their extensive dev teams.

In PP, to change pixelpost tables you can always use addons and there is no need for hacks. In 1.5 we introduce the first version of admin addons that lets you add functions to every corner of the admin code and also you can add new pages and tabs to admin panel (smilar to Wordpress). Pixelpost always can get better and better. Thank you for your suggestions and we will consider them. :)

blinking8s
11-30-2005, 10:07 PM
I'd like to support swf's...but i feel this is something for a split from pixelpost, in a larger future version that someone else can take care of

eon
12-01-2005, 06:47 AM
Can someone look to my hack and advise what is the best to do? So the user gets a smooth install.

You can download the code here (http://193.166.158.251/pixelpost/pixelpost_add_text.zip).
I have add only the pages I made a change on.

You can see the results of the hack here (http://193.166.158.59/pixelpost/).

eon
12-01-2005, 06:52 AM
Can I download Pixelpost 1.5 someware so that I can make my hack ready for that version?

blinking8s
12-01-2005, 07:11 AM
pixelpost 1.5 will launch in publically on the forum when it is in beta...you will have enough time before its official release

eon
12-02-2005, 04:29 PM
I have the install-script for my hack allmost finished.

The working of the script will be like this:
1) upload the script;
2) run the script, the script makes new files;
3) download the new files.

The user can control the new files, maybe edit them some more and upload the new files to the server.

I think this is fast, save and simple.

For the code-lovers there will be an installationmanual to make the hack manual.

Is there anything I forgot?

raminia
12-02-2005, 07:48 PM
I have the install-script for my hack allmost finished.

The working of the script will be like this:
1) upload the script;
2) run the script, the script makes new files;
3) download the new files.

The user can control the new files, maybe edit them some more and upload the new files to the server.

I think this is fast, save and simple.

For the code-lovers there will be an installationmanual to make the hack manual.

Is there anything I forgot?
Well done! Sorry that I was not helpful. I'm dead busy!
Some points:

1) Why downloading them? Showing them online in an editable text area would be nice.

2) do users need to set chmod 777 to includes directory?

eon
12-02-2005, 11:05 PM
Well done! Sorry that I was not helpful. I'm dead busy!
Some points:

1) Why downloading them? Showing them online in an editable text area would be nice.

2) do users need to set chmod 777 to includes directory?

2) I'm not sure if you can save the files because they could be write protected (755 or 744).
My idee was to copy the file to the image directory (always 777), edit the file and save it.
1) After that you can do with the file whatever you want. Download it or showing online in an editable text area. :)
There is also a possibility to automatic delete the file after saving for safety reasons.

eon
12-12-2005, 10:59 PM
When you have made a hack in a php script and you want to share it with other users this script is handy to distibute your hack.

What does the script? The script will search through the php-file, replace parts of code with your new code and save it in a new file. The users can edit or download the new file.

The basis of the php-replace-script is finished.
You can download the script here.
http://www.northing.nl/programs/replace_php.tar.gz

GeoS
12-13-2005, 12:13 PM
Your idea is very dangerous!!! There are many security issues which are hidden for normal user.
It isnt good idea to use it by normal users!!

Connie
12-13-2005, 04:39 PM
eon,

please, whenever a user uses your script and comes to the forum for support and assistance, it is your job to give support ;=)

we, the pixelpost-crew, can not take guarantee for any problems which arise by automatic Search+Replace etc. and we have no manpower to give support for that unfortunately

eon
12-14-2005, 06:16 AM
No problem. I understand. Later I will make a page on northing.nl with more support an how to use this tool.

Is there a way to help your team? Maybe debugging or testing?

eon
12-14-2005, 06:42 AM
Your idea is very dangerous!!! There are many security issues which are hidden for normal user.
It isnt good idea to use it by normal users!!

When a normal user is trying to hack is code. Is it save? I understand that a difficult hack will scare the normal users and then they will not try the hack.
What if the normal user is trying the hack and he/she ask you a lot because he/she don't understand the code?

I will not use the install script to publish my hack. So that you don't get problems with it. The last what I want is to boring you with a program that's not yours ;).

Connie
12-14-2005, 08:04 PM
eon,

as 1.5 BETA is coming nearer, really, we will need people who give us good and detailled report if something goes wrong

so we count on you ;=)