HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Blending box with block and php problem, what am I missing?

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#77673 (In Topic #15972)
Avatar

Fan in action

Hello world!. I searched the site for a few hours and found some great info, but this one's got me stumped. My site links to UStream a few days a week. I use an iframe to do that. I got tired of adding and removing the block on the side bar every week, so today I'm trying to wrote some code that automatically inserts a miniblock only on specified days. It does indeed insert my iframe on the specified day, but I want to put a box around that iframe, and for the life of me, I can't figure out how to do that INSIDE the php, so that the box AND the iframe only show up on the specified day. Here's where I'm at:

My sidebar code looks like this:

Code

[block day="monday" id="8947774"]on_day_do_ustream[/block]
<br />

And my miniblock looks like this:

Code

<?php
    $day = strtolower(date('l'));
    if ($day == strtolower($map['day'])) {
        echo '[box="test" type="panel"]<iframe frameborder="0" height="150" scrolling="no" src="http://www.ustream.tv/embed/';
        echo $map['id'];
        echo '" style="border: 0px none transparent" width="150"></iframe>[/box]
';
    }

?>

When I add the "box=test" to the code, inside the echo statements, to surround the iframe with a box, and save it all, it actually prints literally the "box" code, and does not create a box around my iframe code. I have tried adding some semihtml statements in various places, but that also just prints literally, followed by a correctly displayed iframe of the UStream window. Any ideas how to make my code integrate the box as well as the iframe?
Back to the top
 
Posted
Rating:
#77675
Avatar

Think adding these final lines will work…

Code

$e=ob_get_contents();
ob_clean();
echo static_evaluate_tempcode(put_in_standard_box($e));


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#77681
Avatar

Fan in action

Thanks much, that works well. I saw somewhere in the docs that the function put_in_standard_box should not be used often. I worry that while this code works perfectly, it's a hack. Is there a more preferable way to do this, or is this pretty stable?

I don't see where ob_get_contents gets stuff from, because it takes no arguments. I'm assuming it's getting some sort of global structure and ob_clean must clean the code for echoing. As an amateur programmer, although this works perfectly, I don't know what it actually does, what it "gets" and what it "cleans." Regardless, I'm happy with the results.

I added some arguments to put_in_standard_box so that it would print the title of the box and the type. For others new to OCPortal code, the finished code I used to use a miniblock that prints a box that surrounds an iframe that takes arguments looks like this:

Code

<?php
    $day = strtolower(date('l'));
    if ($day == strtolower($map['day'])) {
        echo '<iframe frameborder="0" height="150" scrolling="no" src="http://www.ustream.tv/embed/';
        echo $map['id'];
        echo '" style="border: 0px none transparent" width="150"></iframe>';
    }
$e=ob_get_contents();
ob_clean();
echo static_evaluate_tempcode(put_in_standard_box($e,$map['title'],'100%','panel'));

and the sidebar code looks like this:

Code

[block day="monday" title="SomeBoxTitle" id="1234567"]on_day_do_ustream[/block]

Now, I'm about to wrap this up and be happy with it, but for one minor detail. When I "edit" the sidebar/sidepanel content, it allows me to "click to edit" a block. Most blocks have arguments, and when you "click to edit" a block, you can edit those arguments by "clicking to edit." However, although my little custom miniblock has 3 arguments, they do not show up as such when I "click to edit" the miniblock. In fact it says something like 'this miniblock has no arguments.' How can I tell the editor that my miniblock has editable arguments, so that I don't have to edit the source code each time?
Back to the top
 
Posted
Rating:
#77684
Avatar

Hey,

Thanks for writing this up, great to see more coding discussion going on around here :).

The put_in_standard_box function is frowned upon because it's hard-encoding an assumption via PHP code. That is the assumption that something will be in an ocPortal standard box.

In your case, your the master of what you're doing, it matters not to you. It's more of a software design issue for us – we tend to encode use of boxes within templates, so that users may easily change that.

ob_* refers to PHP's output buffering. Miniblocks work by turning on output buffering in the ocPortal code, running the miniblock, and then collecting that buffer. That's why you can just echo stuff out into a miniblock. It's not in actuality being echoed into the output stream, it's being buffered and collected by ocPortal.

However in this case, as you need to feed your output through a function, we make use of the buffering already active to collect the buffer contents, empty it, then pipe it through the box function.

Regarding block parameter UIs, that is where you'd need to create a normal block rather than a miniblock. Lots of our addons do this and can serve as examples (e.g. the ebay addon) - get that, then examine the files inside the tar in a text editor. The normal blocks are PHP classes that define lots of extra stuff that define the behaviour of the block somewhat. Also there are associated language strings for putting out the descriptions for the defined parameters.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: