App_Frontend::layout_Content PHP Method

layout_Content() public method

public layout_Content ( )
    public function layout_Content()
    {
        $this->template->trySet('pagename', 'page-' . $this->page);
        $layout = $this->layout ?: $this;
        // TODO: refactor using pathfinders 4th argument to locate = null,
        // to avoid exceptions as those might be expensive.
        // This function initializes content. Content is page-dependant
        $page = str_replace('/', '_', $this->page);
        $page = str_replace('-', '', $page);
        $class = 'page_' . $page;
        if ($this->app->page_object) {
            // page is already initialized;
            return;
        }
        if (method_exists($this, $class)) {
            $this->page_object = $layout->add($this->page_class, $page);
            $this->{$class}($this->page_object);
        } else {
            $class_parts = explode('_', $page);
            $funct_parts = array();
            $ns = '';
            if ($this->namespace_routes[$page]) {
                $ns = $this->namespace_routes[$page] . '\\';
                $class = 'page_index';
            } else {
                while (!empty($class_parts)) {
                    array_unshift($funct_parts, array_pop($class_parts));
                    if ($ns1 = $this->namespace_routes[implode('_', $class_parts)]) {
                        $ns = $ns1 . '\\';
                        $page = implode('_', $funct_parts);
                        $class = 'page_' . $page;
                        break;
                    }
                }
            }
            try {
                $this->app->pathfinder->loadClass($ns . $class);
            } catch (Exception_PathFinder $e) {
                // page not found, trying to load static content
                try {
                    $this->loadStaticPage($this->page);
                    if ($this->layout) {
                        $this->layout->template->tryDel('has_page_title');
                    }
                } catch (Exception_PathFinder $e2) {
                    $class_parts = explode('_', $page);
                    $funct_parts = array();
                    while (!empty($class_parts)) {
                        array_unshift($funct_parts, array_pop($class_parts));
                        $fn = 'page_' . implode('_', $funct_parts);
                        if (!empty($class_parts)) {
                            $in = $ns . 'page_' . implode('_', $class_parts);
                        } else {
                            $in = $ns . 'page_index';
                        }
                        if ($in == 'page_') {
                            $in = 'page_index';
                        }
                        try {
                            $this->app->pathfinder->loadClass($in);
                        } catch (Exception_PathFinder $e3) {
                            continue;
                        }
                        // WorkAround for PHP5.2.12+ PHP bug #51425
                        // @todo Maybe this can be removed because we don't support PHP 5.2 anymore
                        $tmp = new $in();
                        if (!method_exists($tmp, $fn) && !method_exists($tmp, 'subPageHandler')) {
                            continue;
                        }
                        $this->page_object = $layout->add($in, $page);
                        /** @type Page $this->page_object */
                        if (method_exists($tmp, $fn)) {
                            $this->page_object->{$fn}();
                        } elseif (method_exists($tmp, 'subPageHandler')) {
                            if ($this->page_object->subPageHandler(implode('_', $funct_parts)) === false) {
                                break;
                            }
                        }
                        return;
                    }
                    $e->addMoreInfo('static_page_error', $e2->getText());
                    // throw original error
                    $this->pageNotFound($e);
                }
                return;
            }
            // i wish they implemented "finally"
            $this->page_object = $layout->add($ns . $class, $page, 'Content');
            /** @type Page $this->page_object */
            if (method_exists($this->page_object, 'initMainPage')) {
                $this->page_object->initMainPage();
            }
            if (method_exists($this->page_object, 'page_index')) {
                $this->page_object->page_index();
            }
        }
    }