Example #1
0
    /**
     * This function builds the content of the <code>body</code>.
     *
     * @access public
     * @author kalmer
     * @param string         $parameters['alias']          the alias
     * @param string[string] $parameters['breadcrumb']     the breadcrumb as
     * 		links and texts
     * @param boolean        $parameters['broad']          Do we show the broad
     * 		page?
     * @param string         $parameters['content']        the content to be
     * 		displayed on the page
     * @param boolean        $parameters['error']          Are we in the error
     * 		state?
     * @param boolean        $parameters['facebookOnline'] Is Facebook online?
     * @param string         $parameters['id']             the ID of the object
     * 		(optional)
     * @param string         $parameters['type']           the type of the
     * 		original object
     * @param integer        $parameters['idOfLanguage']   the ID of the
     * 		language
     * @param boolean        $parameters['intro']          Is it the intro page?
     * @param Page           $parameters['page']           the page
     * @param string         $parameters['suffix']         the suffix
     * @param Human|boolean  $parameters['user']           the current user or
     * 		<code>FALSE</code>
     * @param integer        $parameters['width']          the width
     * @uses ALBUMS                                 for link the widget for the
     * 		Facebook page
     * @uses DEFAULT_LANGUAGE                       for knowing the current
     * 		language
     * @uses DOMAIN                                 for addressing
     * @uses Language                               for translations
     * @uses MenuItem                               for menus
     * @uses NestedSet                              for menus
     * @uses NESTED_SET_MENU_FOR_INTRO              for the menu on the intro
     * 		page
     * @uses NESTED_SET_MENU_FOR_LOGGED_IN          for people logged in
     * @uses NESTED_SET_MENU_FOR_MAIN_ADMINISTRATOR for the administration menu
     * @uses NESTED_SET_MENU_FOR_REGISTERED_USER    for registered user
     * @uses NESTED_SET_MENU_MAIN_BUTTONS           for main buttons
     * @uses NESTED_SET_MENU_PUBLIC                 for the public menu
     * @uses NESTED_SET_MENU_WE                     for the menu about us
     * @uses O_FOLDER                               for the templates from "O"
     * @uses OFFLINE                                for displaying different
     * 		content for offline and online
     * @uses RequisitesView                         for requisites
     * @uses HumanView                              for log-in-form
     * @uses View                                   for error handling
     */
    public static function buildBody($parameters)
    {
        require_once O_FOLDER . 'errors/ErrorView.php';
        \PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(new ErrorView(), 'raiseError'));
        require_once 'HTML/Template/IT.php';
        $tpl = new \HTML_Template_IT(sprintf('%1$s/../assets/tpl/%2$u', dirname(__FILE__), $parameters['width']));
        $tpl->loadTemplatefile('body.tpl');
        if (isset($parameters['broad']) || $parameters['width'] < 321) {
            $jsNormal = '';
        } else {
            $templateForJsNormal = new \HTML_Template_IT(sprintf('%1$s/../assets/tpl/%2$u', dirname(__FILE__), $parameters['width']));
            $templateForJsNormal->loadTemplatefile('body.tpl');
            if (!OFFLINE && isset($parameters['facebookOnline'])) {
                $templateForJsNormal->setCurrentBlock('facebook-albums');
                $templateForJsNormal->setVariable(array('SUBFOLDER-FOR-ALBUMS' => ALBUMS));
                $templateForJsNormal->parseCurrentBlock();
            }
            $templateForJsNormal->setCurrentBlock('js-normal');
            $templateForJsNormal->setVariable(array('BEGINNING-OF-URL-IN-JS-NORMAL' => DOMAIN));
            $templateForJsNormal->parseCurrentBlock();
            $jsNormal = $templateForJsNormal->get('js-normal');
        }
        $templateForScripts = new \HTML_Template_IT(O_FOLDER . 'assets/tpl');
        $templateForScripts->loadTemplatefile('page_Kai.tpl');
        $templateForScripts->setCurrentBlock('scripts');
        $templateForScripts->setVariable(array('JS-NORMAL' => $jsNormal));
        $templateForScripts->parse('scripts');
        $isError = isset($parameters['isError']) && $parameters['isError'];
        if (isset($parameters['user']) && is_object($parameters['user']) && !$isError) {
            if (isset($parameters['breadcrumb'])) {
                foreach ($parameters['breadcrumb'] as $link => $val) {
                    $tpl->setCurrentBlock('position');
                    $tpl->setVariable(array('LINK-TO-POSITION' => $link, 'STEP' => end($parameters['breadcrumb
						']) === $val ? 'active' : 'completed', 'VALUE-OF-POSITION' => str_replace(' ', '&#160;', $val)));
                    $tpl->parseCurrentBlock();
                }
            } else {
                if (isset($_SESSION['nestedSets'])) {
                    require_once O_FOLDER . 'puu/NestedSet.php';
                    $nestedSets = explode(',', $_SESSION['nestedSets']);
                    $idOfNestedSet = $nestedSets[count($nestedSets) - 1];
                    $nestedSetForPosition = new NestedSet();
                    $nestedSetForPosition->setId($idOfNestedSet);
                    $nestedSetForPosition->setCompleteNestedSet();
                    $descendantNestedSets = $nestedSetForPosition->getDescendantNestedSets();
                    if (isset($descendantNestedSets[$idOfNestedSet])) {
                        foreach ($descendantNestedSets[$idOfNestedSet]->path as $idNestedSet => $txt) {
                            $elInPath = new NestedSet($idNestedSet);
                            $descendantNestedSetsOfElementInPath = $elInPath->getDescendantNestedSets();
                            if (isset($descendantNestedSetsOfElementInPath[$idNestedSet]->idEl)) {
                                require_once dirname(__FILE__) . '/../puu/SystemMenuItem.php';
                                $menuEl = new SystemMenuItem();
                                $menuEl->setId($descendantNestedSetsOfElementInPath[$idNestedSet]->idEl);
                                $menuEl->setCompleteSystemMenuItem();
                                if (isset($menuEl->page)) {
                                    $href = '?function=loadPage&amp;page=' . $menuEl->page->getId();
                                    $caption = $menuEl->page->title;
                                } else {
                                    $href = strtr($menuEl->ref, '&', '&amp;');
                                    $caption = $menuEl->title;
                                    if (strstr($menuEl->ref, '[ID-OF-USER]') > -1) {
                                        if (isset($_SESSION['User_ID'])) {
                                            $href = str_replace('[ID-OF-USER]', '&amp;idHuman=' . $_SESSION['idUser'], $menuEl->ref);
                                        }
                                    }
                                    if (strstr($menuEl->ref, '[ID-OF-COMPANY]') > -1) {
                                        if (isset($_SESSION['idCompany'])) {
                                            $href = str_replace('[ID-OF-COMPANY]', '&amp;idContact=' . $_SESSION['idCompany'], $menuEl->ref);
                                        }
                                    }
                                }
                                $tpl->setCurrentBlock('position');
                                $tpl->setVariable(array('BEGINNING-OF-URL' => DOMAIN, 'LINK-TO-POSITION' => isset($href) ? $href : '#', 'STEP' => end($descendantNestedSets[$idOfNestedSet]->path) === $txt ? 'active' : 'completed', 'VALUE-OF-POSITION' => str_replace(' ', '&#160;', $caption)));
                                $tpl->parseCurrentBlock();
                            }
                        }
                    }
                }
            }
        }
        $menus = array();
        require_once O_FOLDER . 'puu/SystemMenuItemView.php';
        if ($isError) {
            $buildMenuOfLanguages = FALSE;
        } else {
            $buildMenuOfLanguages = TRUE;
            if (isset($parameters['user']) && is_object($parameters['user'])) {
                require_once O_FOLDER . 'puu/SystemMenuItemView.php';
                if ($parameters['user']->isMainAdministrator()) {
                    $isMainAdministrator = TRUE;
                    $menus['forMainAdministrator'] = SystemMenuItemView::buildMenu(array('alias' => $parameters['alias'], 'block' => '2', 'root' => NESTED_SET_MENU_FOR_MAIN_ADMINISTRATOR, 'suffix' => $parameters['suffix'], 'user' => $parameters['user'], 'width' => $parameters['width']));
                    $menus['loggedIn'] = SystemMenuItemView::buildMenuForLoggedIn(array('alias' => $parameters['alias'], 'user' => $parameters['user'], 'width' => $parameters['width']));
                    $menus['forRegisteredUser'] = SystemMenuItemView::buildMenu(array('alias' => $parameters['alias'], 'block' => 'open', 'root' => NESTED_SET_MENU_FOR_REGISTERED_USER, 'suffix' => $parameters['suffix'], 'user' => $parameters['user'], 'width' => $parameters['width']));
                } else {
                    $isMainAdministrator = FALSE;
                    $menus['loggedIn'] = SystemMenuItemView::buildMenuForLoggedIn(array('alias' => $parameters['alias'], 'user' => $parameters['user'], 'width' => $parameters['width']));
                    $menus['forRegisteredUser'] = SystemMenuItemView::buildMenu(array('alias' => $parameters['alias'], 'block' => 'open', 'root' => NESTED_SET_MENU_FOR_REGISTERED_USER, 'suffix' => $parameters['suffix'], 'user' => $parameters['user'], 'width' => $parameters['width']));
                }
            } else {
                $isMainAdministrator = FALSE;
            }
            // echo ' 679: <pre>';print_r(debug_print_backtrace()); echo '</pre>';
            $idOfObject = $parameters['page']->getId();
            if ($parameters['page']->getTypeOfObject() === 'Page' && ID_OF_OPENING_PAGE != $idOfObject || $parameters['page']->getTypeOfObject() != 'Page' || $isMainAdministrator) {
                $menus['aboutUs'] = SystemMenuItemView::buildMenu(array('alias' => $parameters['alias'], 'block' => 'we', 'root' => NESTED_SET_MENU_WE, 'suffix' => $parameters['suffix'], 'user' => $parameters['user'], 'width' => $parameters['width']));
            }
        }
        $menus['public'] = SystemMenuItemView::buildMenu(array('alias' => $parameters['alias'], 'block' => '1', 'root' => NESTED_SET_MENU_PUBLIC, 'suffix' => $parameters['suffix'], 'user' => $parameters['user'], 'width' => $parameters['width']));
        if ($parameters['page']->getTypeOfObject() === 'Page' && ID_OF_OPENING_PAGE == $idOfObject) {
            $menus['forIntro'] = SystemMenuItemView::buildMenu(array('alias' => $parameters['alias'], 'block' => 'intro', 'root' => NESTED_SET_MENU_FOR_INTRO, 'suffix' => $parameters['suffix'], 'user' => $parameters['user'], 'width' => $parameters['width']));
        }
        $outerNews = array();
        if ($parameters['width'] > 899 && !$isError && !OFFLINE) {
            require_once O_FOLDER . 'magpierss-0.72/rss_fetch.inc';
            $rss = fetch_rss(RSS_FEED);
            if (is_object($rss)) {
                $firstOuterNewsItems = array_slice($rss->items, 0, 1);
                $secondOuterNewsItems = array_slice($rss->items, 1, 1);
                $remainingOuterNewsItems = array_slice($rss->items, 2, 1);
                if ($parameters['width'] > 1301 && $parameters['width'] < 1800) {
                    $additionalClassForOuterNews = 'CaptionInEdge';
                } else {
                    $additionalClassForOuterNews = 'CaptionInWideColumn';
                }
                $outerNews['first'] = BodyView::buildOuterNews(array('class' => $additionalClassForOuterNews, 'outerNewsItem' => $firstOuterNewsItems[0], 'width' => $parameters['width']));
                $outerNews['second'] = BodyView::buildOuterNews(array('class' => $additionalClassForOuterNews, 'outerNewsItem' => $secondOuterNewsItems[0], 'width' => $parameters['width']));
                $outerNews['remaining'] = '';
                foreach ($remainingOuterNewsItems as $remainingItem) {
                    $outerNews['remaining'] .= BodyView::buildOuterNews(array('class' => $additionalClassForOuterNews, 'outerNewsItem' => $remainingItem, 'width' => $parameters['width']));
                }
            }
        }
        if (!OFFLINE && !$isError) {
            require_once O_FOLDER . 'varud/Inquiry.php';
            $inquiry = new \o\Inquiry();
            $currentSupporterLogos = '';
            if (isset($_GET['idEvent']) || isset($_GET['iDOCompetition'])) {
                if (isset($_GET['idEvent'])) {
                    require_once dirname(__FILE__) . '/../o/turniirid/Incident.php';
                    $event = new \o\Incident($_GET['idEvent']);
                } else {
                    $competition = new \o\Competition($_GET['iDOCompetition']);
                    $event = $competition->event;
                }
                foreach ($inquiry->categories as $cat) {
                    $supporterLogos = $event->getLogos($cat['id']);
                    if (sizeOf($supporterLogos) > 0) {
                        $currentSupporterLogos .= BodyView::buildLogos(array('folder' => '/assets/tpl', 'file' => 'page_Kai', 'logos' => $supporterLogos, 'block' => 'current', 'category' => $cat, 'sizes' => array('width' => 132, 'height' => 120), 'widthOfBlock' => 132));
                    }
                }
            } else {
                if ($parameters['width'] > 320) {
                    foreach ($inquiry->categories as $cat) {
                        require_once O_FOLDER . 'turniirid/Incident.php';
                        $supporterLogos = Incident::getActualLogos($cat['id']);
                        if (sizeOf($supporterLogos) > 0) {
                            $currentSupporterLogos .= BodyView::buildLogos(array('folder' => '/assets/tpl', 'file' => 'page_Kai', 'logos' => $supporterLogos, 'block' => 'current', 'category' => $cat, 'sizes' => array('width' => $parameters['width'] > 1301 ? 200 : 122, 'height' => 244), 'widthOfBlock' => $parameters['width'] > 1800 ? 200 : 122));
                        }
                    }
                }
            }
        }
        $menus['mainButtons'] = SystemMenuItemView::buildMenu(array('block' => 'mainButtons', 'root' => NESTED_SET_MENU_MAIN_BUTTONS, 'suffix' => $parameters['suffix'], 'user' => $parameters['user'], 'width' => $parameters['width']));
        $login = '';
        require_once O_FOLDER . 'View.php';
        if (!$isError) {
            require_once O_FOLDER . 'haldus/kasutajad/HumanView.php';
            if (isset($parameters['user']) && is_object($parameters['user']) && $parameters['user']->isLoggedIn(array($parameters['suffix']))) {
                $contentOfLogin = HumanView::buildLoggedIn(array('suffix' => $parameters['suffix'], 'width' => $parameters['width']));
            } else {
                $contentOfLogin = \o\HumanView::buildButtonForLoginForm(array('isDraggable' => FALSE, 'width' => $parameters['width']));
                // 				$login .= HumanView::buildLoginForm(array (
                // 					'functions'               => array (),
                // 					'idOfFieldOfInfo'         => 'messageForLoggingIn',
                // 					'idOfFieldOfInfoOriginal' => '',
                // 					'idOfTarget'              => 'wrapperForLoggingIn',
                // 					'suffix'                  => $parameters['suffix'],
                // 					'width'                   => $parameters['width']
                // 				));
            }
            // echo ' 760: ', $contentOfLogin;
            $login = \o\View::buildTarget(array('buildNavigation' => FALSE, 'content' => $contentOfLogin, 'highSlidable' => FALSE, 'id' => '', 'type' => 'ButtonsOfLogin', 'insertionAddition' => '', 'width' => $parameters['width']));
        }
        // echo ' 772: ', $login;
        if (isset($parameters['broad']) && $parameters['broad']) {
            // 			echo ' 763: ', $parameters['content'];
            $contentOfSite = BodyView::buildBig(array('content' => $parameters['content'], 'width' => $parameters['width']));
        } else {
            $contentOfSite = BodyView::buildNormal(array('content' => $parameters['content'], 'currentSupporterLogos' => $isError ? NULL : $currentSupporterLogos, 'user' => $parameters['user'], 'id' => isset($parameters['id']) ? $parameters['id'] : NULL, 'type' => isset($parameters['type']) ? $parameters['type'] : NULL, 'idOfLanguage' => $parameters['idOfLanguage'], 'login' => $login, 'menus' => $menus, 'outerNews' => $outerNews, 'page' => $parameters['page'], 'rss' => isset($rss) ? $rss : NULL, 'suffix' => $parameters['suffix'], 'width' => $parameters['width']));
        }
        // echo ' 783: ', $contentOfSite;
        if (isset($_SESSION['nestedSets']) && !$isError) {
            $nestedSets = array_reverse(array_slice(explode(',', $_SESSION['nestedSets']), 3));
            foreach ($nestedSets as $nestedSet) {
                require_once O_FOLDER . 'puu/SystemMenuItemView.php';
                $submenu = SystemMenuItemView::buildMenu(array('alias' => $parameters['alias'], 'block' => 'submenu', 'root' => $nestedSet, 'secondLevel' => TRUE, 'suffix' => $parameters['suffix'], 'user' => $parameters['user'], 'width' => $parameters['width']));
                if ($submenu != '') {
                    break;
                }
            }
        }
        if ($parameters['width'] > 1301 && $parameters['width'] < 1800 && !$isError && !isset($parameters['intro'])) {
            $bestPlayers = BodyView::buildBestPlayers(array('suffix' => $parameters['suffix'], 'width' => $parameters['width']));
        } else {
            $bestPlayers = '';
        }
        // echo ' 974: ', FB_BADGE;
        require_once O_FOLDER . 'rekvisiidid/RequisitesView.php';
        // echo ' 833: ', BodyView::buildLanguageMenu(
        // 				array (
        // 					'id'     => isset($parameters['id']) ?
        // 							$parameters['id']: NULL,
        // 					'type'   => $parameters['type'],
        // 					'suffix' => $parameters['suffix'],
        // 					'width'  => $parameters['width']
        // 				)
        // 			);
        // echo ' 855: ', $login;
        $tpl->setCurrentBlock('body');
        $tpl->setVariable(array('BADGE' => FB_BADGE, 'USERNAME-IN-FACEBOOK' => ALBUMS, 'BEST-PLAYERS-IN-BODY' => $bestPlayers, 'CONTENT-OF-SITE' => $contentOfSite, 'CURRENT-SUPPORTER-LOGOS' => isset($currentSupporterLogos) ? $currentSupporterLogos : '', 'HUMAN' => \o\View::buildTarget(array('buildNavigation' => TRUE, 'highSlidable' => TRUE, 'id' => '', 'insertionAddition' => '', 'type' => 'user', 'width' => $parameters['width'])), 'LANGUAGES' => isset($parameters['type']) && $buildMenuOfLanguages ? BodyView::buildLanguageMenu(array('id' => isset($parameters['id']) ? $parameters['id'] : NULL, 'type' => $parameters['type'], 'suffix' => $parameters['suffix'], 'width' => $parameters['width'])) : '', 'LOCATION' => DOMAIN, 'LOGGED-IN' => $login, 'LOGIN' => \o\View::buildTarget(array('buildNavigation' => TRUE, 'highSlidable' => TRUE, 'id' => '', 'idOfDiv' => 'Login', 'insertionAddition' => '', 'type' => 'Login', 'width' => $parameters['width'])), 'MENU-WITH-PRIORITY-LOGGED-IN' => isset($menus['loggedIn']) ? $menus['loggedIn'] : '', 'MENU-WITH-PRIORITY-PUBLIC' => isset($menus['public']) ? $menus['public'] : '', 'REQUISITES' => RequisitesView::buildRequisites(array('user' => $parameters['user'], 'width' => $parameters['width'])), 'SCRIPTS' => $templateForScripts->get('scripts'), 'SUBMENU' => isset($submenu) ? $submenu : ''));
        $tpl->parseCurrentBlock();
        // 		echo ' 866: ', $contentOfSite;
        return $tpl->get('body');
    }