Revision [4334]
This is an old revision of ProgrammingHelp made by GmBowen on 2005-01-09 18:23:50.
Programming Help
Many people work at developing various aspects of code for wikka and yet we often struggle for hours, or even days, to solve programming problems that others in the wikka community know the answer to. Even more of an issue, sometimes coding problems aren't rectified until after initial code releases and feedback from other members lead to new code being posted (which means that the old code might now be running on others' wikka implementations) because the initial developer could not figure out how to solve a problem. To reduce these problems, this page is intended for people to be able to pose programming issues they've encountered and have the opportunity to draw on the knowledge of others' in our community as to how to resolve those issues. There are two sections...."Issues Needing assistance" & "Solved Issues". When a user has either solved an issue on their own that they've posted, or received help on the issue that satisfactorily addresses it, then the solution should be posted and it should be moved from the first to the second category.Issues Needing Assistance
Solved Issues
Multiple copies of actions
Not being able to put multiple copies of an action on a page. Can be caused by multiple copies of the same functions being loaded. Solution: have the functions "included" from a separate file using include_once() which stops repeated loading of the functions. Example where implemented: WikkaForumOnly single copies of generated images on a wikka page
In developing my WikkaGrapher action I have it both generating an image and wikka code (that calls an action) that can be placed on a page to place the graph on the page. The action is below (saved as graph.php) and examples of the code are at http://gmbowen.educ.unb.ca/wiki/wakka.php?wakka=Sandbox5 (the code generating interface is at SandBox6). Only the code for the first image is processed for some reason (as can be seen at Sandbox5). Not surprisingly, I'd like users to be able to place more than one graph on a page. Ideas? The graphing engine is at http://www.phpclasses.org/browse/package/1993.html.<?php
echo '<img src="./scripts/graphmaker.php?'.$code.'><br \>';
?>
echo '<img src="./scripts/graphmaker.php?'.$code.'><br \>';
?>
- Three problems with that code:
- the break tag should be written as <br /> (note the forward slash)
- just like the break tag the img tag should be closed - but isn't: - you need ' />' at the end (not just '>');
- once you do that the main problem causing only one image to appear becomes more visible: the src attribute has only an opening " but not a closing one
- Change the code as follows:
<?phpBTW, why not use the nice features of class.graphic.php to let the user specify the data it needs as separate action parameters and let the class generate the query string? That would be much more user-friendly. That's what OO is all (well, mostly) about: hiding the complexities... (The form is horribly messy though...)--JavaWoman
echo '<img src="./scripts/graphmaker.php?'.$code.'" /><br />';
?>
- you should *blush* again....look at SandBox6 and you'll see I am essentially using his interface....I spent 2 days adapting it so it'd work in wikka & give a preview of the graph. A "save" feature is next (Carlos sent me a copy of his code with that incorporated). And perhaps a series of "if" statements so parameters that are blank are not added onto the string -- GmBowen
- Yes, I commented on that messy form, didn't I? (I even updated the link to it. ;-)) What I meant is that your action (apparently) isn't using the class interface to generate the query. Which makes the action hard to use. You could still have it accept the $code paramater, but at the same time have it accept the actual parameters the class can use to generate the query, so it's easier to directly create and/or update the action as embedded in a page. --JavaWoman
- Well, I couldn't use his interface directly in wikka because it was non-compatible. But I'm generating his code in almost exactly the same way he did (but w/o java scripts), I'm just using post instead of get. In addition, and I'm sure you'll :) at this, I removed the code that was non-compliant (I had a computer science major looking over my shoulder at one point when I was working on this who pointed out what the compliance problem was). It's quite possible that I'm missing your point here, because I do think I'm doing what you're saying I'm not. Hmmmm.... --GmBowen
- How is it not compatible? A class is about the easiest to integrate, I would think. Anyway, show us your action code then so we can see what you are actually doing... --JavaWoman
- Now at GraphMaker. His class had embedded formatting all over the place that threw-off wikka....I'm not sure it's a "true" class in the sense of what one of those is (easily embeddable)....it's more like a single-script standalone program.--GmBowen
- I could tell it was something with the closing tags (by looking at properties there were things at the end of the code that shouldn't be) but I couldn't figure out what. I tried multiple things, and obviously one resulted in the loss of the end '>'. Why does it have to be '/>' and not just '>'?? (there are vagaries to php that vary from html that I'm not clear on). Thanks JW. Works like a charm now.
- Because the html-syntax is <tag></tag> (opening tag - closing tag). There was (and is) no </image> or </br>, and it wasn't necessary in older html-standards, so they defined the form <tag /> for this cases, which opens and closes the tag. --NilsLindenberg
- Hmmm, okay. I'll have to work at remembering that...ugh. Thanks Nils. (Now off to bed). -- GmBowen
- Actually there is a closing tag for every opening tag in XHTML, so </img> exists, and so does </br>. And in XHTML every tag needs to be closed - which implies that every tag also has a closing tag. However when a tag is empty, you can "shortcut-close" it by ending the tag with '<tag/>' instead of closing it with '<tag></tag>'. That's less to type - but an additional advantage is that some browsers (still) don't support the "full" form but do support the "shortcut" form - especially if you use "compatibilty mode" by putting a space before the slash: <tag />. The latter form is what we use in Wikka , to ensure compatibilty with many browsers. --JavaWoman
- Another note: it's probably wise not to have the action accept the $code value blindly; at the very least first build the URL and then URL-encode it to prevent any attacks. Without that, the code is a security risk. (Isn't it surprising how many problems there can be with a single short line of code? ;-)) --JavaWoman
- I need more guidance on this I'm afraid (my non-programming background leaping to the fore ;-) )....do you mean do a urlencode($code) in the graph.php file before the "<img src" statement, or alter the output from graphentry.php somehow, or process it through urlencode before being generated by graphentry.php? (these files now at GraphMaker) -- GmBowen
- No I mean first build the full URL to be used for the src attribute (first part concatenated with $code), then urlencode() that, then use the result for the img src attribute. The $code is not necessarily generated by the class (you don't know that it is!) - it's accepted blindly by this action without checking.
- Okay. I tried this...
$url=urlencode($url);
echo "
";
and it didn't work. So I played around some and found that even if I entered http://gmbowen.educ.unb.ca/wiki%2Fscripts%2Fgraphmaker.php (with the / replaced with % 2 F) then it didn't work. No surprise then that the urlencoded output didn't work. So, I encoded and then decoded it and that seemed to solve the problem (and, I'm assuming, the security issue). Is this acceptable?
CategoryDevelopment