Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
tips: Empty Vanilla output -or- skip normal execution
I'm trying to improve FeedPublisher. Actually it uses
to prevent the normal execution of Vanilla and only output the feeds.
I wrote EmptyVanillaOutput( $page ); to clear all normal output:
As I write this, I imagine I could even redefine the constructors to save some resources.
My questions:
1) What do you think ?
2) Is there a way to inject some code before the instantiation of the global control objects ($Head, $Panel, $Foot, $PageEnd) so I can change the reference to the classes with SetReference() and not be forced to redefine them ?
exit;
to prevent the normal execution of Vanilla and only output the feeds.
I wrote EmptyVanillaOutput( $page ); to clear all normal output:
function EmptyVanillaOutput( $page )
{
global $Context, $Head, $Menu, $Panel, $NoticeCollector, $Foot, $PageEnd;
$ClassNames = array('Head', 'Menu', 'Panel', 'NoticeCollector', 'Filler', 'PageEnd');
switch ( $page )
{
case 'comments.php': $SpecificClassNames = array('CommentGrid', 'DiscussionForm', 'CommentFoot');
case 'search.php': $SpecificClassNames = array('SearchForm');
}
$ClassNames = array_merge( $SpecificClassNames, $ClassNames );
// include the code that define the base classes
foreach( $ClassNames as $ClassName)
{
if (!class_exists($ClassName))
{
$PrefixArray = $Context->Configuration['LIBRARY_NAMESPACE_ARRAY'];
$PrefixArrayCount = count($PrefixArray);
$i = 0;
for ($i = 0; $i < $PrefixArrayCount; $i++)
{
$File = $Context->Configuration['LIBRARY_PATH'].$PrefixArray[$i].'/'.$PrefixArray[$i].'.Control.'.$ClassName.'.php';
if (file_exists($File))
{
include($File);
break;
}
}
}
}
// page dependant new classes
class EmptyCommentGrid extends CommentGrid {
function Render() {}
}
class EmptyDiscussionForm extends DiscussionForm {
function Render() {}
}
class EmptyCommentFoot extends CommentFoot {
function Render() {}
}
class EmptySearchForm extends SearchForm {
function Render() {}
}
// global controls new classes
class EmptyHead extends Head {
function Render() {}
}
class EmptyMenu extends Menu {
function Render() {}
}
class EmptyPanel extends Panel {
function Render() {}
}
class EmptyNoticeCollector extends NoticeCollector {
function Render() {}
}
// class EmptyFoot extends Foot {
// function Render() {}
// }
class EmptyFiller extends Filler {
function Render() {}
}
class EmptyPageEnd extends PageEnd {
function Render() {}
}
foreach( $ClassNames as $ClassName )
{
$Context->ObjectFactory->SetReference( $ClassName, 'Empty'.$ClassName);
}
// redefine main controls
$Head = $Context->ObjectFactory->CreateControl($Context, 'Head');
$Menu = $Context->ObjectFactory->CreateControl($Context, 'Menu');
$Panel = $Context->ObjectFactory->CreateControl($Context, 'Panel');
$NoticeCollector = $Context->ObjectFactory->CreateControl($Context, 'NoticeCollector');
$Foot = $Context->ObjectFactory->CreateControl($Context, 'Filler', 'foot.php');
$PageEnd = $Context->ObjectFactory->CreateControl($Context, 'PageEnd');
}
As I write this, I imagine I could even redefine the constructors to save some resources.
My questions:
1) What do you think ?
2) Is there a way to inject some code before the instantiation of the global control objects ($Head, $Panel, $Foot, $PageEnd) so I can change the reference to the classes with SetReference() and not be forced to redefine them ?
0
This discussion has been closed.
Comments
but I know an extension that needs total Vanilla execution: SimpleCache (that needs feedback by the way)
I'd like to simply skip the normal execution.
2) Ok, it's not possible in Vanilla 1. I can manage without.
But would it be possible to base the Context object on Delegation and add some CallDelegate() before constructing those global control objects ? We would need to read the default.php files of the extensions BEFORE constructing the global controls too. I mean would it be possible in Vanilla 2 ?
EDIT: And about the constructors, it seems that I can't override them without breaking the framework.
I thought it was nice to centralize the code in a cache extension.
The function I wrote on the top of this page seems to work well. I don't understand what the problem is...
2) "can't stop extension controllers to render" agreed, that's the kind of thought I needed. Bad news for me. I tried with your "clean the buffer" trick: just replaced
class EmptyPageEnd extends PageEnd { function Render(){}}
by
class EmptyPageEnd extends PageEnd { function Render(){ ob_end_clean();header("Content-type: text/xml\n");echo( $this->Context->Feed ); } }
and it seems to work well. So now I'm gonna try it with delegates only. It's a shame because we can't prevent (yet!) some processes to be executed if we don't need them.
3) Maybe, but what if I want the output of another extension to be cached too. I'd like to understand why you don't like my SimpleCache idea.
Thanks for the input.