Geeklog Forums

Rob

Anonymous

Is it possible to pass arguments to a php block?? I\'m trying to create an updated poll system where an admin can create a new poll for each topic, there fore I would need to pass the QID to the php block so it knows which poll to show. Of course the Easy work around for this would be to just use a normal block and put the HTML code that the php generates into the block, but then users can send multiple votes quite easily. If it\'s not possible where should I begin looking for a way to make it possible??
-Rob

What I did was replace line 3393 in the lib-common.php file.
(Was) $fretval = $function();
(Replace By) $fretval = $function($A[\'help\'],$A[\'title\'],$A[\'name\']);
So when you make a phpblock_function you have three sources for your functions info -- the title and name of the block and I put any extra arguments that I need in the \"Help File URL\" textfield. I figured that maybe I might make use of the title and name of the block at times so I pass them to the phpblock function as well as what I think of as the argument string - the help URL.
Then, in the \"system/lib-custom.php\" file where the custom phpblocks are kept .....
function phpblock_myFunction($helpVar, $titleVar, $nameVar) {}
.... anyway, that\'s what I did.
Greg.

Can you give an example of using the block\'s title, name, and help file inside a block function?
Instead of passing three parameters, you can pass an array which doesn\'t limit the number. If done globally you don\'t have to mod lib-common.php though personally I don\'t like passing everything as globals.

What I was doing was creating "Embedded Flash" blocks, where I embed a Flash swf file into a block (so to speak). You might have need to embed 4 Flash movies in a page. Then, you'll need to communicate between them (potentially). So, I made a php block which I called "phpblock_embedFlash" ...... the code is at the bottom of this post, bear in mind I'm not finished, I just know what I need to do. I definitely need a working model though, the Flash stuff is the "big deal" for me, not the blog. If down the road there exists a better way than mine I'll cheerfully move to it, I just need something now, not later. So certainly there are going to be better ways than mine to do it, this is just what I did and I'm still working on it. So in this case I first need it working so to see that I only need to pass one variable over, the URL where the Flash swf file is located. In the Geeklog admin section, when you add a php type block there are a number of other fields already available in the interface that don't get used, because I needed to pass an URL type variable, I decided to use that textfield for the info. I started off by adjusting the calling line to include the one variable ...

PHP Formatted Code

function phpblock_myFunction($helpVar){}

... as I only needed one variable to begin with, to make a base working prototype from. Here is the phpblock .....

.... as you can see I've used the variable "$theVars" to represent the location of the swf file - the source. This works fine with one swf in a page, but I need to make this work for more than one, so now I need to set the id's of the flash object so now I need to pass more than one parameter. I still haven't exactly figured out how I want to do it, but my first thoughts were to use the "Help File URL" field in the "Create New Block" view and pass a string of variables like ....
"source=http://mysite.xxx/myfile.swf&id=jabber&width=300&height=300"
... and so on, and then separate it within the phpblock, but then I figured that maybe not in this instance but in other phpblocks that I create I might have a use for the name and title of the block so I added them to the arguments passed, I really haven't given any real attention to how I might alter the interface to better reflect to other users that you can pass arguments. Of course maybe I should just pass the entire $A array like so .....

PHP Formatted Code

function phpblock_myFunction($A){}

.... and perhaps I will, I was just really surprised to find php blocks didn't have a specified state for arguments so I set about doing it and if I don't post things as I do them I never go back and post at all, I'm more interested in moving on to whatever is next. I've only just now started to think about perhaps changing the admin interface pages to better reflect what the fields are for -- as in, make a arguments field for the phpblock that is labelled as such.
Your thoughts?
Greg.
PS I hate the way this page handles code blocks. I did the best I could to make it readable.

If you\'re making independent flash blocks and don\'t need to pass variables among them, you can use normal blocks for display. From what you posted, you want to do more though. I don\'t have much experience in flash to suggest anything different than what I already suggested. Good luck in what you\'re doing.