Adding response for SSE, print preview, modal and popup request

@param Controller &$controller Instantiating controller
@return void
5261
protected function _addSpecificResponse(Controller &$controller) {
		$controller->response->type(['sse' => 'text/event-stream']);
		$controller->response->type(['mod' => 'text/html']);
		$controller->response->type(['pop' => 'text/html']);
		$controller->response->type(['prt' => 'text/html']);
	}
381192
public function initialize(Controller $controller) {
		$this->_controller = $controller;
		if (!$this->_controller->Components->loaded('RequestHandler')) {
			$this->_controller->RequestHandler = $this->_controller->Components->load('RequestHandler');
			$this->_controller->RequestHandler->initialize($this->_controller);
		}
		if (empty($this->modelName)) {
			$this->_model = $this->_controller->{$this->_controller->modelClass};
		} else {
			$this->_model = ClassRegistry::init($this->modelName, true);
			if ($this->_model === false) {
				throw new InternalErrorException(__d('view_extension', 'Invalid name of target model for component'));
			}
		}
		if (!$this->_model->Behaviors->loaded('Tree')) {
			throw new InternalErrorException(__d('view_extension', 'Tree behavior is not loaded'));
		}
	}
1144860
public function initialize(Controller $controller) {
		$this->_controller = $controller;
		if (!$this->_controller->Components->loaded('RequestHandler')) {
			$this->_controller->RequestHandler = $this->_controller->Components->load('RequestHandler');
			$this->_controller->RequestHandler->initialize($this->_controller);
		}
		if (!$this->_controller->Components->loaded('Session')) {
			$this->_controller->Session = $this->_controller->Components->load('Session');
			$this->_controller->Session->initialize($this->_controller);
		}
		if ($this->_controller->Auth->loggedIn() ||
			$this->_controller->RequestHandler->prefers('json')) {
			return;
		}

		$isAuthCfg = $this->_modelSetting->isAuthGroupConfigured();
		if ($isAuthCfg) {
			if ($this->_controller->Session->read('Settings.FirstLogon')) {
				$this->_controller->Session->delete('Settings.FirstLogon');

				return $this->_controller->redirect($this->_controller->Auth->logout());
			}

			return;
		}

		$pluginName = $this->_controller->request->param('plugin');
		$controllerName = $this->_controller->request->param('controller');
		$actionName = $this->_controller->request->param('action');
		if (($pluginName !== 'cake_settings_app') ||
			($controllerName !== 'settings') ||
			($actionName !== 'index')) {
			return;
		}

		$this->_controller->Auth->allow('index');
		$this->_controller->Session->write('Settings.FirstLogon', true);
	}
410621
protected function invokeControllerAction(AbstractController $controller, $action)
    {
        $this->invokePluginsHook(
            'beforeActionInvoked',
            array($this, $this->getRequest(), $controller, $action)
        );
        $response = $controller->$action($this->routeParams);
        if (null === $response) {
            // if the action returns null, we simply render the default view
            $response = array();
        } elseif (!is_string($response)) {
            // if they don't return a string, try to use whatever is returned
            // as variables to the view renderer
            $response = (array)$response;
        }

        // merge the response variables with the existing view context
        if (is_array($response)) {
            $response = array_merge($controller->getViewContext(), $response);
        }

        // whatever we have as a response needs to be encapsulated in an
        // AbstractResponse object
        if (!($response instanceof AbstractResponse)) {
            $response = new Response($response);
        }
        $this->invokePluginsHook(
            'afterActionInvoked',
            array($this, $this->getRequest(), $controller, $action, $response)
        );
        return $response;
    }
50248
public function beforeRender(Controller $controller) {
		if (!class_exists('CakeResque') || !property_exists('CakeResque', 'logs')) {
			return null;
		}

		$logs =  CakeResque::$logs;
		$count = 0;
		foreach ($logs as $l) {
			$count += count($l);
		}

		if ($this->priority > 0) {
			$this->title = __dn('debug_kit_ex', '<b>%d</b> job', '<b>%d</b> jobs', $count, $count);
		}
		return $logs;
	}
730497
private function render()
    {
        echo '
            <style>
            .debugger small {
                border: 1px solid rgba(0,0,0,0.2); 
                opacity: 0.5; 
                padding: 2px 5px; 
                margin-left: 5px; 
                border-radius: 2px;
            }
            </style>';

        echo '<pre class="debugger"><strong>@debug</strong><br>';

        foreach ($this->data as $index => $controller) {
            // Set the class params for each Controller
            $this->controller = $controller;

            // Echo the Controller class name
            echo $controller->class;

            // Echo extends tree if the Controller implements tree
            if ($controller->tree) {
                echo '<small>extends tree</small>';
            }

            echo '<ul>';

            // Render data
            if ($controller->data) {
                $this->renderData();
            }

            // Render methods
            if ($controller->methods) {
                $this->renderMethods();
            }

            echo '</ul>';
        }

        echo '</pre>';
    }
120914
public function displayNiceView($controller = null, $url = '', $action = '')
    {
        if (!$controller) {
            $controller = $this->owner;
        }

        return singleton('director')->create_view($controller, $url, $action);
    }
348176
public function initController(\OWeb\types\Controller $controller = null)
    {

        if ($this->controller == null)
            return;

        Events::getInstance()->sendEvent('Init_Prepare@OWeb\manage\Controller', $this->controller);

        $this->controller->initController();

        Events::getInstance()->sendEvent('Init_Done@OWeb\manage\Controller', $this->controller);

        Events::getInstance()->sendEvent('ActionDist_Prepare@OWeb\manage\Controller', $this->controller);

        //gestion des Actions...
        $source[] = \OWeb\OWeb::getInstance()->get_get();
        $source[] = \OWeb\OWeb::getInstance()->get_post();

        foreach ($source as $get) {
            if (isset($get['action']))
                $this->controller->doAction($get['action']);

            $i = 1;
            while (isset($get['action_' . $i])) {
                $this->controller->doAction($get['action_' . $i]);
                $i++;
            }
        }

        Events::getInstance()->sendEvent('ActionDist_Done@OWeb\manage\Controller', $this->controller);
    }
174645
public function renderPopover($controller, $view)
    {
        // render main evolution graph
        $this->graphType = 'graphEvolution';
        $this->graphMetrics = $this->availableMetrics;
        $view->graph = $controller->getRowEvolutionGraph($fetch = true, $rowEvolution = $this);

        // render metrics overview
        $view->metrics = $this->getMetricsToggles();

        // available metrics text
        $metricsText = Piwik::translate('RowEvolution_AvailableMetrics');
        $popoverTitle = '';
        if ($this->rowLabel) {
            $icon = $this->rowIcon ? '<img height="16px" src="' . $this->rowIcon . '" alt="">' : '';
            $metricsText = sprintf(Piwik::translate('RowEvolution_MetricsFor'), $this->dimension . ': ' . $icon . ' ' . $this->rowLabel);
            $popoverTitle = $icon . ' ' . $this->rowLabel;
        }

        $view->availableMetricsText = $metricsText;
        $view->popoverTitle = $popoverTitle;

        return $view->render();
    }
761881
public function startup(Controller $controller) {
        $this->Controller = $controller;

        // Thrown an exception if accessing an override action without requestAction()
        if (substr($controller->action, 0, 6) === 'admin_' && empty($controller->request->params['override'])) {
            throw new ForbiddenException();
        }

        // Set ACL session
        $user_id = $this->Auth->user('id');

        if (!$user_id || $this->Auth->user(Configure::read('User.fieldMap.status')) == Configure::read('User.statusMap.banned')) {
            return;
        }

        if (!$this->Session->check('Acl')) {
            $roles = ClassRegistry::init('Admin.RequestObject')->getRoles($user_id);
            $isAdmin = false;
            $isSuper = false;
            $roleMap = array();

            foreach ($roles as $role) {
                if (!$isAdmin && $role['RequestObject']['alias'] == Configure::read('Admin.aliases.administrator')) {
                    $isAdmin = true;
                }

                if (!$isSuper && $role['RequestObject']['alias'] == Configure::read('Admin.aliases.superModerator')) {
                    $isSuper = true;
                }

                $roleMap[$role['RequestObject']['id']] = $role['RequestObject']['alias'];
            }

            $this->Session->write('Acl.isAdmin', $isAdmin);
            $this->Session->write('Acl.isSuper', $isSuper);
            $this->Session->write('Acl.roles', $roleMap);
        }

        // Set reported count
        if (Configure::read('Admin.menu.reports')) {
            Configure::write('Admin.menu.reports.count', Admin::introspectModel('Admin.ItemReport')->getCountByStatus());
        }
    }
842052
public function display()
    {
        \http_response_code($this->getResponseCode());
        if ($this->contentType) {
            header('Content-Type: ' . $this->contentType);
        }
        //        header('Content-Length: ' . strlen($this->content));
        if ($this->redirection) {
            header('Location: ' . $this->redirection);
        }
        Events::dispatch('beforeResponseSend', array($this));
        session_write_close();
        print $this->content;
        Profiler::dump();
        Events::dispatch('afterResponseSend', array($this));
    }
898083
public function setController(Controller $controller)
    {
        $this->_Controller = $controller;
        $this->setEventManager($controller->getEventManager());
    }
222530
public function prepareController($controller)
    {
        $response   = $this->getResponse();

        if (!$response) {
            $response = new Response();
        }

        $controller->setView($this->getView())
            ->setResponse($response)
            ->setDependencyContainer($this->getDependencyContainer())
            ->setRequest($this->getRequest());
    }
427603
public function onKernelView(GetResponseForControllerResultEvent $event)
    {
        $request = $event->getRequest();
        if (!$request->attributes->has(RequestMeta::ATTRIBUTE_URI)) {
            return;
        }
        $event->setResponse(
            $this->responseFactory->createResponse(
                $request,
                $event->getControllerResult()
            )
        );
    }
493309
public function render($controller = null)
    {
        // Switch current system active module
        $old = $this->system->active($this);

        // If specific controller action should be run
        if (isset($controller)) {
            /**
             * TODO: This would be removed in next major version, here should be
             * passed real controller method for execution.
             */
            $controller = method_exists($this, iModule::OBJ_PREFIX . $controller)
                ? iModule::OBJ_PREFIX . $controller
                : $controller;

            // Define if this is a procedural controller or OOP
            $callback = array($this, $controller);

            // If this controller action is present
            if (method_exists($this, $controller)) {
                // Get passed arguments
                $parameters = func_get_args();
                // Remove first as its a controller action name
                array_shift($parameters);
                // Perform controller action with passed parameters
                call_user_func_array($callback, $parameters);
            } else {
                throw new ControllerActionNotFound($this->id . '#' . $controller);
            }
        }

        // Output view
        echo $this->output();

        // Restore previous active module
        $this->system->active($old);
    }
269035
private function analyseAction($controller) {
        $urlParam = explode('-', $controller);
        switch (count($urlParam)) {
            case 0:
                break;
            case 1:
                $this->controller = $urlParam[0];
                break;
            case 2:
                $this->controller = $urlParam[0];
                $_REQUEST['_1'] = $_GET['_1'] = $urlParam[1];
                break;
            default:
                $this->controller = $urlParam[0];
                foreach ($urlParam as $k => $v) {
                    if ($k === 0) {
                        continue;
                    }
                    $_REQUEST['_' . $k] = $_GET['_' . $k] = $v;
                }
                break;
        }
    }
637144
private function initialize(AbstractController $controller)
    {
        foreach ($this->initializers as $initializer) {
            if ($initializer instanceof InitializerInterface) {
                $initializer->initialize($controller, $this);
            } else {
                call_user_func($initializer, $controller, $this);
            }
        }
    }