1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
<?php
/**
* This file implements the renderer (EXPERIMENTAL)
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package evocore
*/
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
/**
* Includes:
*/
require_once dirname(__FILE__).'/_class_plug.php';
/**
* Renderer Class
*
* @package evocore
*/
class Renderer extends Plug
{
/**
* Constructor
*
* {@internal Renderer::Renderer(-)}}
*
*/
function Renderer()
{
// Call parent constructor:
parent::Plug( 'renderer' );
}
/**
* Validate renderer list
*
* {@internal Renderer::validate_list(-)}}
*
* @param array renderer codes
* @return array validated array
*/
function validate_list( $renderers = array('default') )
{
$this->init(); // Init if not done yet.
$this->restart(); // Just in case.
$validated_renderers = array();
while( $loop_RendererPlugin = $this->get_next() )
{ // Go through whole list of renders
// echo ' ',$loop_RendererPlugin->code;
switch( $loop_RendererPlugin->apply_when )
{
case 'stealth':
case 'always':
// echo 'FORCED';
$validated_renderers[] = $loop_RendererPlugin->code;
break;
case 'opt-out':
if( in_array( $loop_RendererPlugin->code, $renderers ) // Option is activated
|| in_array( 'default', $renderers ) ) // OR we're asking for default renderer set
{
// echo 'OPT';
$validated_renderers[] = $loop_RendererPlugin->code;
}
// else echo 'NO';
break;
case 'opt-in':
case 'lazy':
if( in_array( $loop_RendererPlugin->code, $renderers ) ) // Option is activated
{
// echo 'OPT';
$validated_renderers[] = $loop_RendererPlugin->code;
}
// else echo 'NO';
break;
case 'never':
// echo 'NEVER';
continue; // STOP, don't render, go to next renderer
}
}
// echo count( $validated_renderers );
return $validated_renderers;
}
/**
* Render the content
*
* {@internal Renderer::render(-)}}
*
* @param string content to render
* @param array renderer codes
* @param string Output format, see {@link format_to_output()}
* @return string rendered content
*/
function render( & $content, & $renderers, $format )
{
$this->init(); // Init if not done yet.
$this->restart(); // Just in case.
// echo implode(',',$renderers);
while( $loop_RendererPlugin = $this->get_next() )
{ // Go through whole list of renders
//echo ' ',$loop_RendererPlugin->code, ':';
switch( $loop_RendererPlugin->apply_when )
{
case 'stealth':
case 'always':
// echo 'FORCED ';
$loop_RendererPlugin->render( $content, $format );
break;
case 'opt-out':
case 'opt-in':
case 'lazy':
if( in_array( $loop_RendererPlugin->code, $renderers ) )
{ // Option is activated
// echo 'OPT ';
$loop_RendererPlugin->render( $content, $format );
}
// else echo 'NOOPT ';
break;
case 'never':
// echo 'NEVER ';
break; // STOP, don't render, go to next renderer
}
}
return $content;
}
}
?>
|