Show
Ignore:
Timestamp:
05/09/06 16:01:17 (7 years ago)
Author:
benoitg
Message:
  • Finish content assignation system
  • Content ordering is now global (network, nodes and everywhere content cand now be in mixed order).
    • Implement 'everywhere' content
    • Change MainUI::apendContent to MainUI::addContent
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/wifidog/classes/MainUI.php

    r1018 r1030  
    7070 */ 
    7171class MainUI { 
    72     /** 
    73      * Available structural display areas where content can be placed 
    74      * 
    75      * @var array 
    76      * @access private 
    77      */ 
    78     private $available_display_areas; 
    7972 
    8073    /** 
     
    8477    * @access private 
    8578    */ 
    86     private $contentArray; 
     79    private $_contentDisplayArray; 
     80 
     81    /** 
     82    * Content to be displayed on the page, before ordering 
     83    * 
     84    * @var array 
     85    * @access private 
     86    */ 
     87    private $_contentArray; 
    8788 
    8889    /** 
     
    104105     * Additional class of the <body> of the HTML page 
    105106     */ 
    106     private $page_name; 
     107    private $_pageName; 
    107108 
    108109    /** 
     
    112113     * @access private 
    113114     */ 
    114     private $html_headers; 
     115    private $_htmlHeaders; 
    115116 
    116117    /** 
     
    120121     * @access private 
    121122     */ 
    122     private $tool_section_enabled = true; 
     123    private $_toolSectionEnabled = true; 
    123124 
    124125    /** 
     
    128129     * @access private 
    129130     */ 
    130     private $footer_scripts = array (); 
    131  
    132         private $shrink_left_area = false; 
     131    private $_footerScripts = array (); 
     132 
     133    private $_shrinkLeftArea = false; 
    133134 
    134135    /** 
     
    151152        $db->execSql($current_content_sql, $rows, false); 
    152153        foreach ($rows as $row) { 
    153             $this->contentArray[$row['display_area']] = ''; 
     154            $this->_contentDisplayArray[$row['display_area']] = ''; 
    154155        } 
    155156    } 
     
    163164     *  
    164165     * @param string $content HTML content to be added to the area 
    165      * 
    166      * @return void 
    167      */ 
    168     public function appendContent($display_area, $content) { 
    169         if (!isset ($this->contentArray[$display_area])) { 
    170             throw new exception(sprintf(_('%s is not a valid structural display area'), $display_area)); 
    171         } 
    172         $this->contentArray[$display_area] .= $content; 
     166     *  
     167     * @param integer $display_order_index The order in which the content should 
     168     * be displayed 
     169     * 
     170     * @return void 
     171     */ 
     172    public function addContent($displayArea, $content, $displayOrderIndex = 1) { 
     173            //echo "MainUI::addContent(): Debug: displayArea: $displayArea, displayOrderIndex: $displayOrderIndex, content: $content<br/>"; 
     174    if (!isset ($this->_contentDisplayArray[$displayArea])) { 
     175            throw new exception(sprintf(_('%s is not a valid structural display area'), $displayArea)); 
     176        } 
     177        $this->_contentArray[] = array ('display_area' => $displayArea, 'display_order' => $displayOrderIndex, 'content' => $content); 
     178    } 
     179 
     180    /** Private compare function for sorting the _contentArray() */ 
     181    private static function _contentArrayCmp($a, $b) { 
     182        if ($a['display_order'] == $b['display_order']) { 
     183            return 0; 
     184        } 
     185        return ($a['display_order'] < $b['display_order']) ? -1 : 1; 
     186    } 
     187 
     188    /** 
     189     * Orders the content and put it in the _contentDisplayArray array 
     190     * 
     191     * @return void 
     192     */ 
     193    private function generateDisplayContent() { 
     194        //pretty_print_r($this->_contentArray); 
     195        usort($this->_contentArray, array ('MainUI', '_contentArrayCmp')); 
     196        foreach ($this->_contentArray as $content_fragment) { 
     197            $this->_contentDisplayArray[$content_fragment['display_area']] .= $content_fragment['content']; 
     198        } 
     199 
     200    } 
     201 
     202    /** 
     203     * Add the content marked "everywhere" from both the current node and the 
     204     * current network. 
     205     * 
     206     * @return void 
     207     */ 
     208    private function addEverywhereContent() { 
     209        global $db; 
     210        // Get all network content and node "everywhere" content 
     211        $content_rows = null; 
     212        $network_id = $db->escapeString(Network :: getCurrentNetwork()->getId()); 
     213        $sql_network = "(SELECT content_id, display_area, display_order, subscribe_timestamp FROM network_has_content WHERE network_id='$network_id'  AND display_page='everywhere') "; 
     214        $node = Node :: getCurrentNode(); 
     215        $sql_node = null; 
     216        if ($node) { 
     217            // Get all node content 
     218            $node_id = $db->escapeString($node->getId()); 
     219            $sql_node = "UNION (SELECT content_id, display_area, display_order, subscribe_timestamp FROM node_has_content WHERE node_id='$node_id'  AND display_page='everywhere')"; 
     220        } 
     221        $sql = "SELECT * FROM ($sql_network $sql_node) AS content_everywhere ORDER BY display_area, display_order, subscribe_timestamp DESC"; 
     222 
     223        $db->execSql($sql, $content_rows, false); 
     224        if ($content_rows) { 
     225            foreach ($content_rows as $content_row) { 
     226                $content = Content :: getObject($content_row['content_id']); 
     227                if ($content->isDisplayableAt($node)) { 
     228                    $this->addContent($content_row['display_area'], $content->getUserUI(), $content_row['display_order']); 
     229                } 
     230            } 
     231        } 
     232 
     233    } 
     234 
     235    /** 
     236    * Check if the tool section is enabled 
     237    * 
     238    * @return bool True or false 
     239    * 
     240    * @access public 
     241    */ 
     242    public function isToolSectionEnabled() { 
     243        return $this->_toolSectionEnabled; 
    173244    } 
    174245 
     
    180251     * @access public 
    181252     */ 
    182     public function isToolSectionEnabled() { 
    183         return $this->tool_section_enabled; 
    184     } 
    185  
    186     /** 
    187      * Check if the tool section is enabled 
    188      * 
    189      * @return bool True or false 
    190      * 
    191      * @access public 
    192      */ 
    193253    public function setToolSectionEnabled($status) { 
    194         $this->tool_section_enabled = $status; 
     254        $this->_toolSectionEnabled = $status; 
    195255    } 
    196256 
     
    209269 
    210270    public function shrinkLeftArea() { 
    211                 $this->shrink_left_area = true; 
    212         } 
     271        $this->_shrinkLeftArea = true; 
     272    } 
    213273 
    214274    /** 
     
    222282     */ 
    223283    public function setPageName($page_name_string) { 
    224         $this->page_name = $page_name_string; 
     284        $this->_pageName = $page_name_string; 
    225285    } 
    226286 
     
    240300    */ 
    241301    public function addFooterScript($script) { 
    242         $this->footer_scripts[] = $script; 
     302        $this->_footerScripts[] = $script; 
    243303    } 
    244304 
     
    253313     */ 
    254314    public function setHtmlHeader($headers_string) { 
    255         $this->html_headers = $headers_string; 
     315        $this->_htmlHeaders = $headers_string; 
    256316    } 
    257317 
     
    281341                    // The user has no permission to access the administrative functions 
    282342                    $_html = _("You do not have permissions to access any administration functions."); 
    283                 } else { 
     343                } 
     344                else { 
    284345                    // Init values 
    285346                    $_sqlAdditionalWhere = ""; 
    286347 
    287348                    // Init ALL smarty values 
    288                                         User::assignSmartyValues($this->smarty, $_currentUser); 
     349                    User :: assignSmartyValues($this->smarty, $_currentUser); 
    289350                    $this->smarty->assign('formAction', ""); 
    290351                    $this->smarty->assign('nodeUI', ""); 
     
    327388        } 
    328389 
    329         $this->appendContent('left_area_middle', $_html); 
     390        $this->addContent('left_area_middle', $_html); 
    330391    } 
    331392 
     
    338399     */ 
    339400    private function getToolContent() { 
    340             // Define globals 
    341     global $session; 
     401        // Define globals 
     402        global $session; 
    342403        global $AVAIL_LOCALE_ARRAY; 
    343404 
     
    354415        $this->smarty->assign('sectionLOGIN', false); 
    355416 
    356                 // Set section of Smarty template 
    357                 $this->smarty->assign('sectionSTART', true); 
    358  
    359                 // Get information about user 
    360                 $_currentUser = User :: getCurrentUser(); 
    361  
    362                                 User::assignSmartyValues($this->smarty, $_currentUser); 
    363  
    364                 $this->smarty->assign('logoutParameters', ""); 
    365                 $this->smarty->assign('loginParameters', ""); 
    366                 $this->smarty->assign('formAction', ""); 
    367                 $this->smarty->assign('toolContent', ""); 
    368                 $this->smarty->assign('accountInformation', ""); 
    369                 $this->smarty->assign('techSupportInformation', ""); 
    370                 $this->smarty->assign('shrinkLeftArea', $this->shrink_left_area); 
    371  
    372                 // Provide Smarty with information about the network 
    373                                 Network::assignSmartyValues($this->smarty); 
    374  
    375                 /* 
    376                  * Provide Smarty information about the user's login/logout status 
    377                  */ 
    378  
    379                 if ($_currentUser != null) { 
    380                     // User is logged in 
    381  
    382                     // Detect gateway information 
    383                     $_gwId = $session->get(SESS_GW_ID_VAR); 
    384                     $_gwAddress = $session->get(SESS_GW_ADDRESS_VAR); 
    385                     $_gwPort = $session->get(SESS_GW_PORT_VAR); 
    386  
    387                     // If gateway information could be detected tell them Smarty 
    388                     if ($_gwId && $_gwAddress && $_gwPort) { 
    389                         $this->smarty->assign('logoutParameters', "&amp;gw_id=".$_gwId."&amp;gw_address=".$_gwAddress."&amp;gw_port=".$_gwPort); 
    390                     } 
    391                 } else { 
    392                     // Detect gateway information 
    393                     $_gwId = !empty ($_REQUEST['gw_id']) ? $_REQUEST['gw_id'] : $session->get(SESS_GW_ID_VAR); 
    394                     $_gwAddress = !empty ($_REQUEST['gw_address']) ? $_REQUEST['gw_address'] : $session->get(SESS_GW_ADDRESS_VAR); 
    395                     $_gwPort = !empty ($_REQUEST['gw_port']) ? $_REQUEST['gw_port'] : $session->get(SESS_GW_PORT_VAR); 
    396  
    397                     // If gateway information could be detected tell them Smarty 
    398                     if (!empty ($_gwId) && !empty ($_gwAddress) && !empty ($_gwPort)) { 
    399                         $this->smarty->assign('loginParameters', "?gw_id=".$_gwId."&amp;gw_address=".$_gwAddress."&amp;gw_port=".$_gwPort); 
    400                     } 
    401                 } 
    402  
    403                 /* 
    404                  * Provide Smarty information for the language chooser 
    405                  */ 
    406  
    407                 // Assign the action URL for the form 
    408                 $this->smarty->assign('formAction', $_SERVER['REQUEST_URI']); 
    409  
    410                 foreach ($AVAIL_LOCALE_ARRAY as $_langIds => $_langNames) { 
    411                     if (Locale :: getCurrentLocale()->getId() == $_langIds) { 
    412                         $_selected = ' selected="selected"'; 
    413                     } else { 
    414                         $_selected = ""; 
    415                     } 
    416  
    417                     $_languageChooser[] = '<option label="'.$_langNames.'" value="'.$_langIds.'"'.$_selected.'>'.$_langNames.'</option>'; 
    418                 } 
    419  
    420                 // Provide Smarty all available languages 
    421                 $this->smarty->assign('languageChooser', $_languageChooser); 
    422  
    423                 /* 
    424                  * Provide Smarty information for the language chooser 
    425                  */ 
    426                   
    427                 // Provide information 
    428                 $this->smarty->assign('accountInformation', sprintf(_("Accounts on %s are and will stay completely free."), Network :: getCurrentNetwork()->getName())); 
    429                 $this->smarty->assign('techSupportInformation', sprintf(_("Please inform us of any problem or service interruption at: %s"), '<a href="mailto:'.Network :: getCurrentNetwork()->getTechSupportEmail().'">'.Network :: getCurrentNetwork()->getTechSupportEmail().'</a>')); 
    430  
    431                 // Compile HTML code 
    432                 $_html = $this->smarty->fetch("templates/classes/MainUI_ToolContent.tpl"); 
    433   
     417        // Set section of Smarty template 
     418        $this->smarty->assign('sectionSTART', true); 
     419 
     420        // Get information about user 
     421        $_currentUser = User :: getCurrentUser(); 
     422 
     423        User :: assignSmartyValues($this->smarty, $_currentUser); 
     424 
     425        $this->smarty->assign('logoutParameters', ""); 
     426        $this->smarty->assign('loginParameters', ""); 
     427        $this->smarty->assign('formAction', ""); 
     428        $this->smarty->assign('toolContent', ""); 
     429        $this->smarty->assign('accountInformation', ""); 
     430        $this->smarty->assign('techSupportInformation', ""); 
     431        $this->smarty->assign('shrinkLeftArea', $this->_shrinkLeftArea); 
     432 
     433        // Provide Smarty with information about the network 
     434        Network :: assignSmartyValues($this->smarty); 
     435 
     436        /* 
     437         * Provide Smarty information about the user's login/logout status 
     438         */ 
     439 
     440        if ($_currentUser != null) { 
     441            // User is logged in 
     442 
     443            // Detect gateway information 
     444            $_gwId = $session->get(SESS_GW_ID_VAR); 
     445            $_gwAddress = $session->get(SESS_GW_ADDRESS_VAR); 
     446            $_gwPort = $session->get(SESS_GW_PORT_VAR); 
     447 
     448            // If gateway information could be detected tell them Smarty 
     449            if ($_gwId && $_gwAddress && $_gwPort) { 
     450                $this->smarty->assign('logoutParameters', "&amp;gw_id=".$_gwId."&amp;gw_address=".$_gwAddress."&amp;gw_port=".$_gwPort); 
     451            } 
     452        } 
     453        else { 
     454            // Detect gateway information 
     455            $_gwId = !empty ($_REQUEST['gw_id']) ? $_REQUEST['gw_id'] : $session->get(SESS_GW_ID_VAR); 
     456            $_gwAddress = !empty ($_REQUEST['gw_address']) ? $_REQUEST['gw_address'] : $session->get(SESS_GW_ADDRESS_VAR); 
     457            $_gwPort = !empty ($_REQUEST['gw_port']) ? $_REQUEST['gw_port'] : $session->get(SESS_GW_PORT_VAR); 
     458 
     459            // If gateway information could be detected tell them Smarty 
     460            if (!empty ($_gwId) && !empty ($_gwAddress) && !empty ($_gwPort)) { 
     461                $this->smarty->assign('loginParameters', "?gw_id=".$_gwId."&amp;gw_address=".$_gwAddress."&amp;gw_port=".$_gwPort); 
     462            } 
     463        } 
     464 
     465        /* 
     466         * Provide Smarty information for the language chooser 
     467         */ 
     468 
     469        // Assign the action URL for the form 
     470        $this->smarty->assign('formAction', $_SERVER['REQUEST_URI']); 
     471 
     472        foreach ($AVAIL_LOCALE_ARRAY as $_langIds => $_langNames) { 
     473            if (Locale :: getCurrentLocale()->getId() == $_langIds) { 
     474                $_selected = ' selected="selected"'; 
     475            } 
     476            else { 
     477                $_selected = ""; 
     478            } 
     479 
     480            $_languageChooser[] = '<option label="'.$_langNames.'" value="'.$_langIds.'"'.$_selected.'>'.$_langNames.'</option>'; 
     481        } 
     482 
     483        // Provide Smarty all available languages 
     484        $this->smarty->assign('languageChooser', $_languageChooser); 
     485 
     486        /* 
     487         * Provide Smarty information for the language chooser 
     488         */ 
     489 
     490        // Provide information 
     491        $this->smarty->assign('accountInformation', sprintf(_("Accounts on %s are and will stay completely free."), Network :: getCurrentNetwork()->getName())); 
     492        $this->smarty->assign('techSupportInformation', sprintf(_("Please inform us of any problem or service interruption at: %s"), '<a href="mailto:'.Network :: getCurrentNetwork()->getTechSupportEmail().'">'.Network :: getCurrentNetwork()->getTechSupportEmail().'</a>')); 
     493 
     494        // Compile HTML code 
     495        $_html = $this->smarty->fetch("templates/classes/MainUI_ToolContent.tpl"); 
     496 
    434497        return $_html; 
    435498    } 
     
    446509     */ 
    447510    public function display() { 
     511 
    448512        // Init values 
    449513        $_stylesheetFile = ""; 
     
    461525 
    462526        // Add HTML headers 
    463         $this->smarty->assign('htmlHeaders', $this->html_headers); 
     527        $this->smarty->assign('htmlHeaders', $this->_htmlHeaders); 
    464528 
    465529        // Asign title 
     
    467531 
    468532        // Asign CSS class for body 
    469         $this->smarty->assign('page_name', $this->page_name); 
     533        $this->smarty->assign('page_name', $this->_pageName); 
    470534 
    471535        // Asign path to CSS stylesheet 
     
    477541        if (is_file(NODE_CONTENT_PHP_RELATIVE_PATH.STYLESHEET_NAME)) { 
    478542            $_stylesheetFile = NODE_CONTENT_SMARTY_PATH.STYLESHEET_NAME; 
    479         } else { 
     543        } 
     544        else { 
    480545            $_stylesheetFile = DEFAULT_CONTENT_SMARTY_PATH.STYLESHEET_NAME; 
    481546        } 
     
    490555 
    491556        // Get information about user 
    492                 User::assignSmartyValues($this->smarty); 
    493  
    494                 $this->appendContent('page_header', $this->customBanner()); 
    495  
     557        User :: assignSmartyValues($this->smarty); 
     558 
     559        //Handle content 
     560 
     561        $this->addContent('page_header', $this->customBanner()); 
    496562        /* 
    497563         * Build tool pane if it has been enabled 
    498564         */ 
    499565        if ($this->isToolSectionEnabled()) { 
    500             $this->appendContent('left_area_top', $this->getToolContent()); 
    501         } 
    502  
     566            $this->addContent('left_area_top', $this->getToolContent()); 
     567        } 
     568        $this->addEverywhereContent(); 
     569        $this->generateDisplayContent(); 
    503570        // Provide the content array to Smarty 
    504         $this->smarty->assign('contentArray', $this->contentArray); 
     571        $this->smarty->assign('contentDisplayArray', $this->_contentDisplayArray); 
    505572 
    506573        // Provide footer scripts to Smarty 
    507         $this->smarty->assign('footerScripts', $this->footer_scripts); 
     574        $this->smarty->assign('footerScripts', $this->_footerScripts); 
    508575 
    509576        // Compile HTML code and output it 
     
    523590     */ 
    524591    function displayError($errmsg, $show_tech_support_email = true) { 
    525         // Init ALL smarty values 
    526         $this->smarty->assign("error", ""); 
     592            // Init ALL smarty values 
     593    $this->smarty->assign("error", ""); 
    527594        $this->smarty->assign("show_tech_support_email", false); 
    528595        $this->smarty->assign("tech_support_email", ""); 
     
    541608        $_html = $this->smarty->fetch("templates/sites/error.tpl"); 
    542609 
    543         $this->appendContent('page_header', $_html); 
     610        $this->addContent('page_header', $_html); 
    544611        $this->display(); 
    545612    } 
    546613 
    547         static public function redirect($redirect_url, $redirect_to_title=null, $timeout=60) { 
    548                 if (!$redirect_to_title) { 
    549                         $network = Network :: getCurrentNetwork(); 
    550                         $redirect_to_title = $network ? sprintf(_("%s Login"), $network->getName()) : _("Login"); 
    551                 } 
    552  
    553                 header("Location: $redirect_url"); 
    554                 echo "<html>\n" . 
    555                         "<head><meta http-equiv='Refresh' content='$timeout; URL=$redirect_url'/></head>\n". 
    556                         "<body>\n" . 
    557                         "<noscript>\n" . 
    558                         "<span style='display:none;'>\n" . 
    559                         "<h1>" . $redirect_to_title . "</h1>\n" . 
    560                         sprintf(_("Click <a href='%s'>here</a> to continue"), $redirect_url) . "<br/>\n" . 
    561                         _("The transfer from secure login back to regular http may cause a warning.") . "\n" . 
    562                         "</span>\n" . 
    563                         "</noscript>\n" . 
    564                         "</body>\n" . 
    565                         "</html>\n" 
    566                         ; 
    567                 exit; 
    568         } 
    569  
    570         public function customBanner() { 
    571                 $custom_banner = ''; 
    572  
    573                 return $custom_banner; 
    574         } 
     614    static public function redirect($redirect_url, $redirect_to_title = null, $timeout = 60) { 
     615        if (!$redirect_to_title) { 
     616            $network = Network :: getCurrentNetwork(); 
     617            $redirect_to_title = $network ? sprintf(_("%s Login"), $network->getName()) : _("Login"); 
     618        } 
     619 
     620        header("Location: $redirect_url"); 
     621        echo "<html>\n"."<head><meta http-equiv='Refresh' content='$timeout; URL=$redirect_url'/></head>\n"."<body>\n"."<noscript>\n"."<span style='display:none;'>\n"."<h1>".$redirect_to_title."</h1>\n".sprintf(_("Click <a href='%s'>here</a> to continue"), $redirect_url)."<br/>\n"._("The transfer from secure login back to regular http may cause a warning.")."\n"."</span>\n"."</noscript>\n"."</body>\n"."</html>\n"; 
     622        exit; 
     623    } 
     624 
     625    public function customBanner() { 
     626        $custom_banner = ''; 
     627 
     628        return $custom_banner; 
     629    } 
    575630} 
    576631