[pmwiki-users] Embed Sporcle
Peter Bowers
pbowers at pobox.com
Tue Mar 15 08:49:57 CDT 2011
On Tue, Mar 15, 2011 at 2:20 PM, Steve Glover <steve.glover at ed.ac.uk> wrote:
> On 15/03/11 11:31, Hans wrote:
>>
>> Tuesday, March 15, 2011, 11:11:14 AM, Mark Trumpold wrote:
>>
>>> Is there a way it could be site wide? From what I understand you
>>> saying is that it is a page only directive
>>
>> just use the (:sporcle:) markup directive whereever
>> you want to embed the game. The markup definition in config.php
>> is for all pages (site wide).
>
> If you are using different games on different pages the simple\\\\\\ easy
> approach would be to have
>
> (:sporcle:) (:sporcle1:) (:sporcle2:) etc....
I would suggest using arguments instead - much more flexible:
(:sporcle gid=1234 pid=2345asdf1234:)
Or, if non-technical users might be putting this markup in then you
could define a name for each game on a separate page:
===(snip Site.Sporcle)===
states: gid=1234 pid=2345asdf2345
europe: gid=3465 pid=1234wert32
disciples: gid=5423 pid=5423trew4321
===(snip)===
In the first option you would simply use ParseArgs() over the arguments:
===(snip)===
$SporcleFmt = '
<iframe frameborder="0" scrolling="no" marginheight="0"
marginwidth="0" id="spFrame"
src="http://www.sporcle.com/framed/?gid={{gid}}&pid={{pid}}"
width="860"></iframe>
<script type="text/javascript">function
rIF(ht){document.getElementById("spFrame").height=parseInt(ht)+40;}</script>
';
Markup('sporcle', 'directives' '/\\(:sporcle(.*?):\\)/e',
"Sporcle('$1')");
function Sporcle($args)
{
global $SporcleFmt;
$opts = ParseArgs($args);
$foo = str_replace(array('{{gid}}', '{{pid}}'), array($opts['gid'],
$opts['pid']), $SporcleFmt);
return(Keep($foo));
}
===(snip)===
or, using the second method, you would have to read that page:
===(snip)===
$SporcleFmt = '
<iframe frameborder="0" scrolling="no" marginheight="0"
marginwidth="0" id="spFrame"
src="http://www.sporcle.com/framed/?gid={{gid}}&pid={{pid}}"
width="860"></iframe>
<script type="text/javascript">function
rIF(ht){document.getElementById("spFrame").height=parseInt(ht)+40;}</script>
';
SporcleDefPage = 'Site.Sporcle';
Markup('sporcle', 'directives' '/\\(:sporcle(.*?):\\)/e',
"Sporcle(\$pagename, '$1')");
function Sporcle($pagename, $args)
{
global $SporcleFmt, $SporcleDefPage;
$ptv = trim($args);
$opts = ParseArgs(PageTextVar($SporcleDefPage, $ptv));
$foo = str_replace(array('{{gid}}', '{{pid}}'), array($opts['gid'],
$opts['pid']), $SporcleFmt);
return(Keep($foo));
}
===(snip)===
Be aware I may have messed up my single- and double-quotes up there...
Also the usual "email-ware" caveat is in full force here...
Hope that helps.
-Peter
PS BTW, Mark, thanks for introducing me to yet another way to waste my
time... :-)
More information about the pmwiki-users
mailing list