•  · 22 friends

Is UNA really limiting code inserts? No it isn't. Just read this ;)

What I observe here is a frequent complain "how to put code in our pages?!" "it is not possible!"

The method below is a super easy way to insert any code to your pages.

1. Create a raw block, position it where ever you like your code to appear in your UNA page. In that block only write a unique and strong place holder for instance *my?cod!e123*.

2. Go to page.php have a backup copy. replace these lines as described:

if ($oPage) {
$oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
$oTemplate->setPageType ($oPage->getType());
$oTemplate->setPageContent ('page_main_code', $oPage->getCode());
$oTemplate->getPageCode();
} else {
$oTemplate->displayPageNotFound();
}

change to:

if ($oPage) {
$oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
$oTemplate->setPageType ($oPage->getType());
$oTemplate->setPageContent ('page_main_code', $oPage->getCode());}
else {
$oTemplate->displayPageNotFound();}
ob_start();
$oTemplate->getPageCode();
$currentpage = ob_get_clean();
now you have the html in your hand at $currentpage which is about to send to the browsers. Just replace your placeholder with your code, and echo the current page :) that's all.

$currentpage= str_replace ('*my?cod!e123*','ANY CODE',$currentpage);
echo $currentpage;

with this simple method you will open a big free area and use UNA's abilities with less restriction. Codes are from UNA 9.0, but there will not be so much change in the mechanism.

Advantages are:

 you don't touch Una code and dont mix the page.

You can insert any code of yours

You may use the parameters like user id etc from Una functions as they are already loaded at the beginning of the page.

You may use the same block on different positions and pages.

Safety is measured by how safe your own code is.

Heading title padding background can be set by Una block settings


1
  • 106
Replies (4)
  • Be careful with this code, if some user adds the text *mycode123* in any place(Discussion topic, Discussion text, Photo name, Album name, Their own name, etc), it will be replaced as well.

    If you really need this, you should add a really difficult combination instead of *mycode123*.

    Senior Developer.

    • Yes of course,  it should be "unique" and  better a bit complex in real production environment :)

      • It's better to use service blocks instead. Service block can call any user's created code. 

        • I will check it Alex thank you.

          3
          1
          1
          Labels:
          Added:
          Category: