I was wondering what would be best to use to achieve the following:
I have a section in the control panel to edit the actual views/ files. i can add what ever i want directly trough the control panel and then save it to the file in the server. What i want to do is build something like an expressions tag. So if a member types:
{expression type="content" id="2" /}
if would parse the contents of the content with the ID 2 (from the database) .
thing is i will need to run a check on all the output before it's printed to replace those with the right value. Does any one know what will be the best way of doing this? is there a function i can override to add things needed to be done just before the output is printed to the member?
is this something that a widget could do? or a filter? or any other way?
I see so lets say for example i have the following:
<?php
class PerformanceFilter extends CFilter
{
protected function preFilter($filterChain)
{
// logic being applied before the action is executed
return true; // false if the action should not be executed
}
protected function postFilter($filterChain)
{
// logic being applied after the action is executed
}
}
How would i make it run on every single action of a controller located only in the controllers/site/ directory? I cannot set an action list for that filter since i have tons of actions spread across several controller files.
You just need to declare the filter in your controller's filters() method. No need to list actions because by default, the filter would be applied to every action.
public function filters()
{
return array(
'application.filters.PerformanceFilter',
);
}
to my BaseSiteController that extends MasterController -> CController
And i get the following error:
Filter "application.filters.PerformanceFilter" is invalid. Controller "IndexController" does have the filter method "filterapplication.filters.PerformanceFilter".
Great! it worked. Now how would i go on to actually have inside a variable the entire output?
Like i did:
<?php
class TestFilter extends CFilter
{
protected function preFilter($filterChain)
{
// logic being applied before the action is executed
print "test";
return true; // false if the action should not be executed
}
protected function postFilter($filterChain)
{
// logic being applied after the action is executed
}
}
And it did print everything. I would like to perform regular expressions on the entire output how can i actually have the entire output?
I read the CHTMLPurifier class reference but for a lack of examples i couldn't really understand the usage. Besides i will need to extend the COutputProcessor, CHtmlPurifier, CFilter all in the same classs, Which i obvious can't. How would i go on doing this? Would appreciate some more details.
You just need to extend COutputProcessor and override its processOutput() method like CHtmlPurifier does. In this method, the input parameter is the captured output that you want to process. After processing, you simply return the processed result.