02: Order! Order!

This is a temporary forum setup for the purpose of discussing the EMC standards
Locked
Nuttzy99
Registered User
Posts: 927
Joined: Fri Aug 03, 2001 7:09 am
Contact:

02: Order! Order!

Post by Nuttzy99 » Tue Sep 02, 2003 2:20 am

Order! Order!

The least you need to know:
  • files are processed sequentially
  • FIND once and operate many
  • work sequentially from before to after
[/b]
Files
Just to be clear on this, whenever you use OPEN it is intended that a files are processed sequentially. You should never FIND something that is towards the bottom of the file followed by FINDing something that is before it. For example if you FIND something on line 100, you are going to fail if you try FINDing something on line 99. Also it assumed that you will only OPEN a files once.

FINDing and IN-LINE FINDing
For both FIND and IN-LINE, you must only attempt to FIND a block or fragment once. Once it is found you may perform as many relevant actions on it that you can. Therefore FIND -> BEFORE, ADD -> IN-LINE FIND -> IN-LINE BEFORE, ADD is valid. Unfortunately a previously acceptable method of keeping each command contained within its own block can no longer be allowed. For example the following is now unacceptable: FIND -> BEFORE, ADD -> FIND (the same line) -> IN-LINE FIND -> IN-LINE BEFORE A full explanation for this is here.

Commands
A rule of thumb when manipulating code around a FIND block is to work sequentially from before to after. The only real reason for this is because a FIND block is committed to the file after performing an AFTER, ADD and no other commands can occur on that FIND block.

So if you had several commands to do after the FIND, the best sequence would be BEFORE, ADD -> IN-LINE commands *or* REPLACE -> AFTER, ADD. The same applies for IN-LINE FIND. The commands are best ordered as IN-LINE BEFORE, ADD -> IN-LINE REPLACE -> IN-LINE AFTER, ADD.

Lastly, remember that IN-LINE commands go with IN-LINE FIND and the other commands (like AFTER, ADD) go with FIND. You cannot mix and match the commands. For example, and AFTER, ADD command will not add text after an IN-LINE FIND fragement, it can only add completely new lines after a FIND block.

-Nuttzy :cool:
SpellingCow.com - Free spell check service for your forums or any web form!
My Other Site

Ptirhiik
Registered User
Posts: 144
Joined: Sun Apr 06, 2003 12:29 pm

Re: 02: Order! Order!

Post by Ptirhiik » Tue Sep 02, 2003 6:11 am

How is handled a multi fragmented line find, and in-lines treatement of different lines of this find ? ie:

Code: Select all

#---[ FIND ]-----
$sql = "SELECT * FROM " .
      WHERE foo1=
     ORDER BY foo2";
With an action on the select line and one action on the where line (assuming of course this find is the only way to catch as unique the select statement and where statement, which occurs quite often in phpBB scripts).

Nuttzy99
Registered User
Posts: 927
Joined: Fri Aug 03, 2001 7:09 am
Contact:

Re: 02: Order! Order!

Post by Nuttzy99 » Tue Sep 02, 2003 2:06 pm

It is completely fine to have multiple IN-LINE FINDs on a single FIND block. The only requirement is that you should do them in the order they appear. It really doesn't matter the order for making several changes to the same line. But it does matter if you are making changes to multiple lines that you do the earlier lines first. Once IN-LINE FIND detects that the fragment is not on the line it is looking at, it writes the line to the file b/c it figures it is done with the line. This approach is also useful in cases where you have fragments that are somewhat similar on multiple lines. You can simply do an IN-LINE FIND on something unique about the second line in order to have the first one committed to the file.

I plan on documenting this in a section for IN-LINE FIND.

-Nuttzy :cool:
SpellingCow.com - Free spell check service for your forums or any web form!
My Other Site

Nuttzy99
Registered User
Posts: 927
Joined: Fri Aug 03, 2001 7:09 am
Contact:

Re: 02: Order! Order!

Post by Nuttzy99 » Tue Sep 02, 2003 2:08 pm

Hrmmmm.... just read your comment again and I think further explaination is needed. FIND simply is used to FIND the lines. Once the lines are found, the entire text of the lines are available for searching by IN-LINE FIND, not just the fragments from the FIND statement.

I should probably better explain this in the FIND documentation.

-Nuttzy :cool:
SpellingCow.com - Free spell check service for your forums or any web form!
My Other Site

Ptirhiik
Registered User
Posts: 144
Joined: Sun Apr 06, 2003 12:29 pm

Re: 02: Order! Order!

Post by Ptirhiik » Tue Sep 02, 2003 5:45 pm

Do you mean that the result of the FIND block is considered as an unique line (not several lines) for treatement, as if the carriage returns won't there ?

Nuttzy99
Registered User
Posts: 927
Joined: Fri Aug 03, 2001 7:09 am
Contact:

Re: 02: Order! Order!

Post by Nuttzy99 » Tue Sep 02, 2003 6:05 pm

No.

Here's an example though. You have a FIND block like this...

Code: Select all

# 
#-----[ FIND ]------------------------------------------ 
#
# NOTE: the origial text is like:
#	$sql = "UPDATE " . USERS_TABLE . "
#		SET " . $username_sql ... [ follow by much more ]
#		WHERE user_id = $user_id";
#
$sql = "UPDATE " . USERS_TABLE
user_sig_bbcode_uid = '$signature_bbcode_uid',
WHERE
...which is considered unique enough. Now let's say you want to perform and IN-LINE FIND. For this you are not limited to the small amount of text, but instead the entirety of the lines....

Code: Select all

$sql = "UPDATE " . USERS_TABLE . "
				SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) ."', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_sig_bbcode_uid = '$signature_bbcode_uid', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_notify_pm = $notifypm, user_popup_pm = $popuppm, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_active = $user_active, user_actkey = '" . str_replace("\'", "''", $user_actkey) . "'" . $avatar_sql . "
				WHERE user_id = $user_id";
...so for example you could do an IN-LINE FIND on user_notify_pm even though it is not explicitly stated in the FIND command.

-Nuttzy :cool:
SpellingCow.com - Free spell check service for your forums or any web form!
My Other Site

Ptirhiik
Registered User
Posts: 144
Joined: Sun Apr 06, 2003 12:29 pm

Re: 02: Order! Order!

Post by Ptirhiik » Tue Sep 02, 2003 6:15 pm

The question was more this one : would I be allowed to consider the three lines found as an unique line for the in-line find, so chaining this :

Code: Select all

#--- [ IN-LINE FIND ]-------
$username_sql
#---[ IN-LINE AFTER, ADD]----
some stuff
#---[ IN-LINE FIND ]------
user_id =
#---[ IN-LINE BEFORE, ADD ]-----
some other stuff

Nuttzy99
Registered User
Posts: 927
Joined: Fri Aug 03, 2001 7:09 am
Contact:

Re: 02: Order! Order!

Post by Nuttzy99 » Tue Sep 02, 2003 6:18 pm

That will work fine. Don't call it a "line" though, call it a block of lines or "block". You can do as many IN-LINE commands as are needed on a single FIND block.

-Nuttzy :cool:
SpellingCow.com - Free spell check service for your forums or any web form!
My Other Site

Ptirhiik
Registered User
Posts: 144
Joined: Sun Apr 06, 2003 12:29 pm

Re: 02: Order! Order!

Post by Ptirhiik » Tue Sep 02, 2003 6:23 pm

hum.. Are you sure this is correctly parsed by the actual version of easymod ? :)

Nuttzy99
Registered User
Posts: 927
Joined: Fri Aug 03, 2001 7:09 am
Contact:

Re: 02: Order! Order!

Post by Nuttzy99 » Tue Sep 02, 2003 6:31 pm

From the version of CF that has been downloaded and installed easily over 1000 times by EM....

Code: Select all

#
#-----[ FIND ]------------------------------------------ 
#
# from the sql statement:	$sql = "INSERT INTO " . USERS_TABLE . "	(user_id...
#					VALUES ($user_id, ...
#
$sql = "INSERT INTO " . USERS_TABLE
VALUES (


#
#-----[ IN-LINE FIND ]------------------------------------------ 
#
user_from,


#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------ 
#
 user_from_flag,


#
#-----[ IN-LINE FIND ]------------------------------------------ 
#
'" . str_replace("\'", "''", $location) . "',


#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------ 
#
 '$user_flag',
.... this is from includes/user_register.php... the original lines are....

Code: Select all

$sql = "INSERT INTO " . USERS_TABLE . "	(user_id, username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_sig_bbcode_uid, user_avatar, user_avatar_type, user_viewemail, user_aim, user_yim, user_msnm, user_attachsig, user_allowsmile, user_allowhtml, user_allowbbcode, user_allow_viewonline, user_notify, user_notify_pm, user_popup_pm, user_timezone, user_dateformat, user_lang, user_style, user_level, user_allow_pm, user_active, user_actkey)
				VALUES ($user_id, '" . str_replace("\'", "''", $username) . "', " . time() . ", '" . str_replace("\'", "''", $new_password) . "', '" . str_replace("\'", "''", $email) . "', '" . str_replace("\'", "''", $icq) . "', '" . str_replace("\'", "''", $website) . "', '" . str_replace("\'", "''", $occupation) . "', '" . str_replace("\'", "''", $location) . "', '" . str_replace("\'", "''", $interests) . "', '" . str_replace("\'", "''", $signature) . "', '$signature_bbcode_uid', $avatar_sql, $viewemail, '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', '" . str_replace("\'", "''", $yim) . "', '" . str_replace("\'", "''", $msn) . "', $attachsig, $allowsmilies, $allowhtml, $allowbbcode, $allowviewonline, $notifyreply, $notifypm, $popup_pm, $user_timezone, '" . str_replace("\'", "''", $user_dateformat) . "', '" . str_replace("\'", "''", $user_lang) . "', $user_style, 0, 1, ";
...so :P and :wink:

-Nuttzy :cool:
SpellingCow.com - Free spell check service for your forums or any web form!
My Other Site

Locked