Example #1
0
 /**
  * adds the toolbar to the html dom before closing body tag
  * 
  * @access public
  * @static
  * @param \Smarty $oView
  * @return void
  */
 public static function injectToolbar(\Smarty $oView)
 {
     $sToolBarVarName = 'sToolBar_' . uniqid();
     $sInfoToolSmarty = '{$' . $sToolBarVarName . '}';
     // add toolbar template var to layout
     $aToolbar = \MVC\Registry::get('aToolbar');
     $oView->assign('aToolbar', $aToolbar);
     $oView->assign($sToolBarVarName, $oView->loadTemplateAsString(realpath(__DIR__ . '/../') . '/templates/infoTool.tpl'));
     // disable regular view output
     \MVC\View::$_bEchoOut = FALSE;
     // inject toolbar var to regular string output via DOM
     INJECT:
     $oDom = new \DOMDocument(null, null);
     // prevent error messages occuring by using DOM
     // @see http://stackoverflow.com/a/6090728/2487859
     libxml_use_internal_errors(true);
     // DOMDocument::loadHTML will treat your string as being in ISO-8859-1 unless you tell it otherwise.
     // @see http://stackoverflow.com/a/8218649/2487859
     $oDom->loadHTML(mb_convert_encoding($aToolbar['sRendered'], 'HTML-ENTITIES', 'UTF-8'));
     libxml_clear_errors();
     // add toolbar tag as a placeholder before body closing tag
     $oNode = $oDom->createElement($sToolBarVarName);
     $oBody = $oDom->getElementsByTagName('body');
     foreach ($oBody as $oItem) {
         $oItem->appendChild($oNode);
     }
     $sHtml = $oDom->saveHTML();
     // render the toolbar
     $sInfoToolRendered = $oView->fetch('string:' . $sInfoToolSmarty);
     // replace toolbar tag placeholder with rendered toolbar
     $sHtml = str_replace('<' . $sToolBarVarName . '></' . $sToolBarVarName . '>', $sInfoToolRendered, $sHtml);
     // new output, now including toolbar
     echo $sHtml;
 }