TinyPortal

Development => Resources => Topic started by: Ayan on July 24, 2009, 12:43:51 PM

Title: Weird php block reaction
Post by: Ayan on July 24, 2009, 12:43:51 PM
I've recenly written a guild recruitment block for my website (still in testing, not live).

I wrote the code in Notepad with a little help from a php editor (for syntax highlighting/troubleshooting).

Baically, it's written so that when you put an "A" through "E" next to the class you're trying to recruit, it echo's a priority on the front page for that class.

Code: [Select]
// Class Status
// Your class status should reflect the highest need based on the spec priority.
// A = Closed - no longer accepting
// B = Low - Recruiting this class, but on a select basis
// C = Medium - Recruiting this class, needed to fufill a group role (Tank, Mele, Ranged, Healing)
// D = High - Recruiting this class, imperitive to fufill class rolls
// E = Open - Recruiting members of this class, regardless of need

$class_dkn = A;
$class_dru = B;
$class_hun = C;
$class_mag = D;
$class_pal = E;
$class_pri = A;
$class_rog = B;
$class_sha = C;
$class_wal = D;
$class_war = E;

Pretty simple, right?

When I change a letter and cut the entire code from Notepad and paste it into the php block, it works perfectly.  When I go into the block code and individually change a letter without repasting the entire code, the whole block breaks, and I get random code scattered all over my frontpage. 

Anyone else run into this problem?
Title: Re: Weird php block reaction
Post by: JPDeni on July 24, 2009, 12:51:35 PM
I would use the php editor instead of Notepad. Or edit the code in the block itself. I've had really poor luck with Notepad.
Title: Re: Weird php block reaction
Post by: Ayan on July 24, 2009, 01:32:01 PM
I did a complete rewrite of the code in the editor, and it still only works with a cut and paste.  I'm going to need to be able to change the strings in the php block, because there will be six people with access to change the status as  needed.

At fist I was thinking it may be a problem with the length of code, but since it works fine with the cut and paste, I'm ruling that out.
Title: Re: Weird php block reaction
Post by: JPDeni on July 24, 2009, 01:47:45 PM
Have you tried other php code in another block?
Title: Re: Weird php block reaction
Post by: Ayan on July 24, 2009, 02:19:13 PM
Yes.  I have another block for raid progress which requires changing the strings in the same way to show which bosses have been killed, attempted, and not attempted.  When I change these in the php block, it works fine.
Title: Re: Weird php block reaction
Post by: Ayan on July 24, 2009, 02:23:49 PM
I have 3 sets of strings that are designed to be altered.  If I change any string in any of the three sets (all affect the block differently by design), the php block reacts the same way.  So, hopefully, I've ruled out a program error causing only one section of the block to go haywire.
Title: Re: Weird php block reaction
Post by: JPDeni on July 24, 2009, 02:55:57 PM
So it's not an issue with TP and it's not an issue with the logic of your code. The only other possibility is that something has been corrupted somewhere, either in your code or in your database.

I would delete the block in question and try it again.
Title: Re: Weird php block reaction
Post by: Ayan on July 24, 2009, 03:26:14 PM
I'll give it a shot.  Thanks!
Title: Re: Weird php block reaction
Post by: Ayan on July 24, 2009, 04:00:39 PM
OK.  Deleted the old block.  Just recreated the block in a different php editor.  Copied it in, good.  Made a change in the block editor, and the problem returned.

I'm using UTF-8 encoding for everything.  Could that be be the cause of the problems?
Title: Re: Weird php block reaction
Post by: JPDeni on July 24, 2009, 04:05:26 PM
Quote
I'm using UTF-8 encoding for everything.  Could that be be the cause of the problems?

It could be. I've never used it myself, so I don't know anything about it. I'm a "try it and see" sort of programmer, so I'd probably change the encoding and see what happens.
Title: Re: Weird php block reaction
Post by: Ayan on July 24, 2009, 04:35:28 PM
Haha.  Tested on a live site with the UTF-8 encodings, and no joy.  So, I guess I'll have to go back over everything again.
Title: Re: Weird php block reaction
Post by: Ayan on July 25, 2009, 08:16:23 PM
I finally found the problem!  Now to solve the root issue.  I'm using a mouseover tooltip (wz tooltip) to display images out of an array.  In order to make the tooltip work, all of the HTML double quotes (") need to be converted to the HTML character entity (").  Like this:

Code: [Select]
Correct:
'thumb' => '<img src=&quot;/images/class_spec/lds.jpg&quot;>',
Incorrect:
'thumb' => '<img src="/images/class_spec/lds.jpg">',

When I copy the code into the block and hit save, the php script works flawlessly.  When I go back in to edit one of the recruiting requirements, Tiny Portal (or whatever is handling the script) converts all of the (&quot;) back to (") which "breaks" the  scripting.


So, anyone know a way around this problem?
Title: Re: Weird php block reaction
Post by: JPDeni on July 25, 2009, 08:47:37 PM
Ah-ha!

Well, I congratulate you on finding the problem. I'm not sure what to change, though. I'll see if maybe Bloc will have some ideas.
Title: Re: Weird php block reaction
Post by: Ayan on July 25, 2009, 11:21:53 PM
I'd appreciate it.  Thanks!   I didn't know that HTML could change like that, but I'm learning.   I cut out all of the data arrays except one to work with, and   I spotted it quite by accident, when I was going over every line.  Oddly, that was the last place I was looking for a problem to crop-up.  I have been doing some looking on my own, but haven't found any references to this specific problem, unless I'm googling it using inappropiate terminology.

I'm wondering if a better option wouldn't be to store the arrays in a seperate file and try to call them with the display part of the coding.  But, I can see that getting really messy really fast trying to update variables into a block, sending it to a file to define the variables in the arrays and sending it back to the block to create the display.

Maybe I'm up way too late puzzling this out and will program myself into hell trying to work on it any more tonight, lol.  Besides, I don't think the boss will buy the "No, Really!  I wound up trapped in Hell!" excuse if I come in late for work tomorrow.
Title: Re: Weird php block reaction
Post by: JPDeni on July 26, 2009, 06:42:37 AM
:D

I did a little bit of looking and it appears that the "culprit" is the use of html_entity_decode when the blocks and articles are saved. If you want to be brave :) you can try going into the Sources/TPortalAdmin.php file and remove that function. There are several places where it exists, but you probably only need to worry about the one that deals with blocks, which appears to be the line

Code: [Select]
$context['TPortal']['blockedit']['body']=html_entity_decode($row['body']);

Try changing it to

Code: [Select]
$context['TPortal']['blockedit']['body']=$row['body'];

and see what happens. If you get a crash, change it back.
Title: Re: Weird php block reaction
Post by: Ayan on July 26, 2009, 05:05:22 PM
Wow, finding such a function is pretty amazing.  Alas, to no avail.  My next step was to go through and backup every TP file, and search them for the html_entity_decode function, and remove them all.... from every TP file I could find.  Still, it is decoding the entity.  Are there any other files I should look at?  For instance, does SMF have an overriding factor here?

PS.  Search engine results on this are negative for Tiny Portal, except a few entries in portugese or swahili.
Title: Re: Weird php block reaction
Post by: JPDeni on July 27, 2009, 07:50:54 AM
I had another thought. You might be able to get it to work by altering your php code a bit.

Instead of

Code: [Select]
'thumb' => '<img src=&quot;/images/class_spec/lds.jpg&quot;>',

Try setting a variable
Code: [Select]
$quote = '&quot;';

and then using it in your array

Code: [Select]
'thumb' => '<img src=' . $quot . '/images/class_spec/lds.jpg' . $quot . '>',
Title: Re: Weird php block reaction
Post by: Ayan on July 27, 2009, 08:51:26 AM
That's an interesting take.  I'll give it a shot.  You may have helped me inadvertently with another... "coding of convienience" problem I was working on for a few hours last night.  I was unable to get a variable string working inside if the <img src=***> last night at all, even using a few examples of snippets I found in the snippets board.  I may end up owing you a batch of cookies....
Title: Re: Weird php block reaction
Post by: JPDeni on July 27, 2009, 09:15:01 AM
LOL!

There is a problem with creating textareas in forms in a php script as well and this is similar to the workaround I figured out for that. I just remembered it when I woke up this morning. Sometimes things need to "fester" a while in my brain. ;)
Title: Re: Weird php block reaction
Post by: Ayan on July 27, 2009, 09:21:57 AM
That was a really creative solution to that problem, JPDeni.  Bonus that I didn't have to alter the core TP files to do it.  I'm really starting to appreciate how flexible this language is.  If I had any pull, I'd nominate you for the Nobel 'php'iece Prize.  Guess you'll have to settle for cookies!  PM me where to send them :-)

Now that it works (as intended), time to make it look pretty.... Doh!

BT-Dubs, you solved my other "code of convienience"  issue too.  Let's hope when I get this home to my SMF 1.1.10/TP 1.0 B4, it continues to work!
Title: Re: Weird php block reaction
Post by: JPDeni on July 27, 2009, 09:23:41 AM
Excellent! I'm really glad it worked for you.

Don't worry about the cookies. I'm trying to cut down. But I appreciate the thought.  :-*
Title: Re: Weird php block reaction
Post by: Ayan on July 27, 2009, 03:08:04 PM
Haha!  No one ever wants the cookies!  I've been trying to get rid of them for years now...
Title: Re: Weird php block reaction
Post by: JPDeni on July 27, 2009, 03:44:30 PM
LOL!!!!  :2funny: :2funny: :2funny:
Title: Re: Weird php block reaction
Post by: Ayan on July 28, 2009, 05:03:10 PM
Well, thanks again for all of the help.  Here is where I was going with all of this:

http://www.foulplayers.net/index.php (http://www.foulplayers.net/index.php)

The second and third blocks on the left-hand side for Raid Progression and Recruitment.

Page load times are a little slow.  I need to beat my host around the head with a boat paddle...

Still some design tweaks to go, but it's all functional now.
Title: Re: Weird php block reaction
Post by: JPDeni on July 28, 2009, 05:21:06 PM
Looks great!