1 troy Jul 27, 2007 21:44
3 troy Jul 27, 2007 22:11
I want to execute it, but I want it to be in the form of a post and not ever-present on every page of my blog. It's a long quiz-type thing where people make selections and then it calculates how much webspace you'd need. I'd pack it into another file but I still have to use script tags, which b2evo refuses to accept in my post.
Do I HAVE TO put the js code in the head of my main.php so the form can call it? I plan to have a few posts like this and the unused code could really build up there so I hat this idea of having the code on every page for a form on only one.
4 afwas Jul 27, 2007 22:58
Ok. Now I have a clearer understanding of your goal.
We're going to fool the XHTML checker to allow <script> tags. Open the named ../blogs/conf/_formatting.php
After line 231 add:
'script' => E_Iinline,
This allows the tag <script> to exist. It can have the values described in E_Iinline. E_Iinline id described in line 115:
define('E_Iinline', '#PCDATA '.E_inline.' '.E_misc_inline );
which are the values #PCDATA plus the values in E_inline and in E_misc_inline.
You get the idea.
Then after line 289 AND after line 318:
$allowed_attributes = array
you can add a line similar to the lines that exist. Here you can place special tags that you need in your specific script.
Fill this line until you get no more error notices after posting your script.
Do try to call your script through the #PCDATA method. Search Google for JavaScript and XHTML. That way your work in the _formatting.php file is less tedious.
Happy coding.
5 troy Jul 28, 2007 01:55
I'm sorry but I'm not really sure what I should do. I added the script tag all three places so theoretically it should be allowed, but I'm still getting:
* Tag <script> must occur inside another tag
* Tag <script> may not have attribute type
* Tag <script> may not contain raw character data
* Tag <script> may not contain raw character data
* Tag <script> may not contain raw character data
* Tag <script> may not contain raw character data
* Parser error: XML_ERR_NAME_REQUIRED near ar years = 0;
var x
I don't really know what you mean by
Do try to call your script through the #PCDATA method. Search Google for JavaScript and XHTML. That way your work in the _formatting.php file is less tedious.
but I googled it and found this
http://javascript.about.com/library/blxhtml.htm
so I implemented it. No real change there. I don't really know any PHP so I'm completely lost here.
6 afwas Jul 28, 2007 08:50
Obvious I didn't give you a clearcut solutions but a clue as to how you should proceed. Luckily you provided the errors so we can get more to the point. Let's start at the end:
You found a right page. You are best off if you try to embed your JS as:
<script type="text/javascript">
<![CDATA[
// content of your Javascript goes here
]]>
</script>
The CDATA is raw data that should be ignored by the XHTML parser (your browser and I mean in a way thet it doesn't print but that it does execute) and hopefully by the file _formatting.php.
To fool _formatting.php there are only three problems:
* Tag <script> must occur inside another tag
* Tag <script> may not have attribute type
* Tag <script> may not contain raw character data
I am puzzled by the first. Come bach to this later.
The second is easy near line 289 AND 318 it sais:
$allowed_attributes = array
you add a line similar to:
'script' => A_attrs.' type',
On to the second. I Googled [url=http://www.w3schools.com/dtd/dtd_building.asp]This page[/url]. It sais we must ignore PCDATA and add CDATA. We can redefine our new input line near 289 AND 318 to:
'script' => A_attrs.' type #CDATA',
With a little luck it should now only give the
* Tag <script> must occur inside another tag
error. We can overcome this by changing the
'script' Arrow E_Iinline,
near line 231. Try changing it to
'script' Arrow E_Flow,
.Like <h1> (also E_Flow) the tag doesn't NEED to be nested.
To get your code going, you can temporarily disable the XHTML checker altogether in line 45:
$use_html_checker = 1;
Change the 1 to 0. Be careful. Don't do this is in a high frequent visited blog but in a testblog instead. At least you then know your JS is embedded correctly.
Good luck
7 edb Jul 28, 2007 10:18
You might also want to turn off the "Auto-P" plugin for the posts you're trying this on. That will stop your post content from being inside a P tag, which might be why it's upset with a tag in a tag. Maybe!
8 afwas Jul 28, 2007 11:07
I am looking into this topic (try to get some JS to work on my testblog) but don't expect a fast answer because I am also out for the weekend.
9 troy Jul 28, 2007 18:27
Still not working for me. I think I'll re-upload the original _formatting.php file and put this one on hold, I'm worried I've already screwed something ujp :P
10 yabba Jul 28, 2007 19:17
You might like to try the plugin in [url=http://forums.b2evolution.net/viewtopic.php?t=9349&postdays=0&postorder=asc&&start=0]this post[/url]
I can't remember if the zip it links to is the current version, if it doesn't work just give me a shout and I'll update the zip ;)
¥
11 afwas Aug 01, 2007 13:27
Thanks for the plugin. It's the one I was looking for if I only knew it excisted.
One question: How do I display text in the body of a post, in other ords, what DOM do I call and how?
12 yabba Aug 01, 2007 13:45
We are a tad slow at releasing our plugins :p
With the current version of the plugin you'd be able to do something like :
<!--script
window.onload = function(x){
var the_post = document.getElementById( '%post%' );
var the_text = document.createTextNode( 'hello world' );
the_post.appendChild( the_text );
}
-->
ish :p
It wouldn't be hard to modify the plugin to allow javascript in the body of the post as well, let me know if that's something you'd want
¥
13 afwas Aug 01, 2007 13:58
¥åßßå wrote:
It wouldn't be hard to modify the plugin to allow javascript in the body of the post as well, let me know if that's something you'd want
¥
Yes, that's the idea and not only mine, but also Troy's, who wants to do a Q & A type of thing.
14 yabba Aug 01, 2007 14:19
Have a play with this and see if it does what you want.
If you want to make something post specific just use %post% and it'll be replaced with am_custom_post_##
ie/
<div id="%post%">Hello world</div>
<!--css
#%post%{
text-align:center;
}
-->
<!--script
// this is in <head>
// of course this'll fail because it's in <head> ;)
window.alert( document.getElementById( '%post%' ) );
-->
<!--js
// this is wherever it appears in your post content
// but this one won't ..... as long as it's at the end of your post ;)
window.alert( document.getElementById( '%post%' ) );
-->
¥
*edit*
ffs .txt is not allowed as an attachment
15 afwas Aug 05, 2007 05:33
I have one small addition:
in ../blogs/conf/_formatting.php set
$posts_allow_css_tweaks = true;
to allow the 'id' tag within the post. Turn it off (false) within comments makes it a tad safer.
One neat example I got working:
<!--js
function changeColor(newColor)
{
elem = document.getElementById("%post%");
elem.style.color = newColor;
}
-->
<p id="%post%">Hello World</p>
<button onclick="changeColor('blue');">blue</button>
<button onclick="changeColor('red');">red</button>
<noscript><br /><br />EdB sees the world in B/W</noscript>
although this could also be done placing the code in <head>
¥åßßå, thanks, you rock.
16 yabba Aug 05, 2007 09:00
I keep forgetting that most people have id & style disabled, it's one of the first things I add on an upgrade ( hence the easy setting ;) )
¥
You want your readers to view the code but not execute it, am I right? You should try a plugin called [url=http://www.crammerz-inc.net/blogs/thunk/2007/05/26/b2evolution_code_highlighter_plugin]Genshi[/url] or the one called [url=http://b2evo.astonishme.co.uk/index.php?p=32]Display Code Plugin[/url] or [url=http://www.blog.cingusoft.com/index.php/all/2006/11/25/cgeshi_highlight_code_with_geshi]CGeshi[/url]. Just pick the one that suits your needs.
In the file ../blog/conf/formatting.php you find on line 48:
If it is set to 1 no code will be allowed (see also the XHTML checker and the comments in the file).
If you want to execute it, you'd be better of packing it in a .js file and call it from the _main.php. Use Google for the various possibilities.
Good luck