<?php
require_once OCS_APPLICATION_PATH . '/controllers/Abstract/Filter.php';

class Ocs_Controller_FilterController
    extends Ocs_Controller_Abstract_Filter
{
    public function headStartAction()
    {
        ob_start();
    }

    public function headStopAction()
    {
        $content = ob_get_clean();

        /**
        * Temporarily disable content filtering that might be called from get_the_excerpt
        */
        Ocs_WpPlugin::setDisableFilterContent(TRUE);

        echo Ocs_Application::getService('Optimization')
            ->setPostId(Ocs_WpPlugin::getCurrentPostId())
            ->filterHead(array(
                'type'    => 'head',
                'content' => $content,
            ));

        /**
        * Now enable content filtering back
        */
        Ocs_WpPlugin::setDisableFilterContent(FALSE);
    }

    public function headStopHomeAction()
    {
        $content = ob_get_clean();

        echo Ocs_Application::getService('Optimization')
            ->filterHomeHead(array(
                'content' => $content,
            ));
    }

    public function contentAction()
    {
        $service = Ocs_Application::getService('Optimization')
            ->setPostId(Ocs_WpPlugin::getCurrentPostId());

        $result = $service->filterContent(array(
            'type'    => 'content',
            'content' => $this->getParam('content'),
        ));

        /*
        $service->dispose();
        Ocs_Application::unloadSingleton('Optimization', 'service');
        */

        return $result;
    }
}