Changeset 1091

Show
Ignore:
Timestamp:
09/06/06 10:58:06 (4 years ago)
Author:
benoitg
Message:

* Remove most inclusions of MainUI in classes. That completely
broke authentication (circular dependencies). Fixes 245.

Unfixes 242. Exceptions should not be caught in the context

they are thrown in. Else there no point in throwing exception in the
first place.
* HyperLink?.php: Fix bug where a link with identical text as
it's link would see the text replaced by the clickthrough-tracked
equivalent.

Location:
trunk/wifidog-auth
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/CHANGELOG

    r1090 r1091  
     12006-09-06 Benoit Grégoire  <bock@step.polymtl.ca> 
     2 
     3        * HyperLink.php:  Fix bug where a link with identical text as it's link would see the text replaced by the clickthrough-tracked equivalent. 
     4 
    152006-09-06 Benoit Grégoire  <bock@step.polymtl.ca> 
    26        * ContentTypeFilter:  New class, implements #159.  Allows to filter content type according to various criteria.  Will be used more extensively in the profile manager. 
     
    1115        * At last, working content scheduled display and expiration for ContentGroups.  Archiving does not yet have a UI.  Content that expires will simply seem to disapear. 
    1216        * Fix #247 (somebody filed a bug before I commited, conveniently saving me the need to describe it).     
    13         * The Fix for #106 in [1089] returned non-objects, causing error messages and not displaying what it was meant to display.    
     17        * The Fix for #106 in [1089] returned non-objects, causing error messages and not displaying what it was meant to display.  
     18                Used Guest instead of Annonymous, which will probably be used for different purpose in the future.   
    1419                This re-fix does not include duplicate counting yet.  Splash users are not the only users that could log-in multiple times.   
    1520                I don't have a staging server here, a fix will be commited in a few minutes if something goes wrong. 
  • trunk/wifidog-auth/wifidog/classes/Content.php

    r1090 r1091  
    5151require_once ('classes/Cache.php'); 
    5252require_once ('classes/HyperLink.php'); 
    53 require_once ('classes/MainUI.php'); 
    5453 
    5554/** 
     
    724723        } 
    725724 
    726         try { 
    727725            if (!User :: getCurrentUser()) { 
    728726                throw new Exception(_('Access denied!')); 
    729727            } 
    730         } catch (Exception $e) { 
    731             $ui = new MainUI(); 
    732             $ui->setToolSection('ADMIN'); 
    733             $ui->displayError($e->getMessage(), false); 
    734             exit; 
    735         } 
    736728 
    737729        if ($type_interface != "table") { 
  • trunk/wifidog-auth/wifidog/classes/Content/ContentGroup/ContentGroupElement.php

    r1090 r1091  
    11<?php 
     2 
    23 
    34/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
     
    4950 * Load required classes 
    5051 */ 
    51 require_once('classes/Content/ContentGroup/ContentGroup.php'); 
    52 require_once('classes/Node.php'); 
     52require_once ('classes/Content/ContentGroup/ContentGroup.php'); 
     53require_once ('classes/Node.php'); 
    5354 
    5455/** 
     
    6061 * @copyright  2005-2006 Benoit Grégoire, Technologies Coeus inc. 
    6162 */ 
    62 class ContentGroupElement extends Content 
    63 { 
    64  
    65     /** 
    66  
    67      */ 
    68     private $content_group_element_row; 
    69  
    70     /** 
    71      * Constructor 
    72      * 
    73      * @param string $content_id Content Id 
    74      * 
    75      * @return void     */ 
    76     protected function __construct($content_id) 
    77     { 
    78         // Define globals 
    79         global $db; 
    80  
    81         // Init values 
    82         $row = null; 
    83  
    84         parent :: __construct($content_id); 
    85         $content_id = $db->escapeString($content_id); 
    86  
    87         $sql_select = "SELECT * FROM content_group_element WHERE content_group_element_id='$content_id'"; 
    88         $db->execSqlUniqueRes($sql_select, $row, false); 
    89  
    90         if ($row == null) { 
    91             // The database was corrupted, let's fix it ... 
    92             $sql = "DELETE FROM content WHERE content_id='$content_id'"; 
    93             $db->execSqlUpdate($sql, true); 
    94         } 
    95  
    96         $this->content_group_element_row = $row; 
    97  
    98         /* A content group element is NEVER persistent */ 
    99         parent::setIsPersistent(false); 
    100     } 
    101     /** When a content object is set as Simple, it means that is is used merely to contain it's own data.  No title, description or other metadata will be set or displayed, during display or administration 
    102      * @return true or false */ 
    103     public function isSimpleContent() { 
    104         return true; 
    105     } 
    106     /** 
    107      * Replace and delete the old displayed_content (if any) by the new 
    108      * content (or no content) 
    109      * 
    110      * @param object $new_displayed_content Content object or null. If 
    111      *                                      null the old content is still 
    112      *                                      deleted. 
    113      * 
    114      * @return void 
    115  
    116      */ 
    117     private function replaceDisplayedContent($new_displayed_content) 
    118     { 
    119         // Define globals 
    120         global $db; 
    121  
    122         // Init values 
    123         $old_displayed_content = null; 
    124         $errmsg = null; 
    125  
    126         if (!empty ($this->content_group_element_row['displayed_content_id'])) { 
    127             $old_displayed_content = self :: getObject($this->content_group_element_row['displayed_content_id']); 
    128         } 
    129  
    130         if ($new_displayed_content != null) { 
    131             $new_displayed_content_id_sql = "'".$new_displayed_content->GetId()."'"; 
    132         } else { 
    133             $new_displayed_content_id_sql = "NULL"; 
    134         } 
    135  
    136         $db->execSqlUpdate("UPDATE content_group_element SET displayed_content_id = $new_displayed_content_id_sql WHERE content_group_element_id = '$this->id'", FALSE); 
    137  
    138         if ($old_displayed_content != null) { 
    139             $old_displayed_conten->delete($errmsg); 
    140         } 
    141     } 
    142  
    143     /** 
    144      * Get the order of the element in the content group 
    145      * 
    146      * @return string the order of the element in the content group 
    147      */ 
    148     public function getDisplayOrder() 
    149     { 
    150         return $this->content_group_element_row['display_order']; 
    151     } 
    152  
    153     /** 
    154      * Set the order of the element in the content group 
    155      * 
    156      * @param string $order Order how items should be displayed 
    157      * 
    158      * @return void 
    159      */ 
    160     public function setDisplayOrder($order) 
    161     { 
    162         // Define globals 
    163         global $db; 
    164  
    165         if ($order != $this->getDisplayOrder()) { 
    166             /* 
    167              * Only update database if there is an actual change 
    168              */ 
    169             $order = $db->escapeString($order); 
    170             $db->execSqlUpdate("UPDATE content_group_element SET display_order = $order WHERE content_group_element_id = '$this->id'", false); 
    171         } 
    172     } 
    173  
    174     /** 
    175      * Like the same method as defined in Content, this method will create a 
    176      * ContentGroupElement based on the content type specified by 
    177      * getNewContentUI OR get an existing element by getSelectExistingContentUI 
    178      * 
    179      * @param string $user_prefix                A identifier provided by the programmer to 
    180      *                                           recognise it's generated form 
    181      * @param string $content_group              Must be present 
    182      * @param bool   $associate_existing_content If set to true, will get an 
    183      *                                           existing element instead of creating a 
    184      *                                           new content. 
    185      * 
    186      * @return object The ContentGroup object, or null if the user didn't greate one 
    187      * @static 
    188      */ 
    189     public static function processNewContentUI($user_prefix, ContentGroup $content_group, $associate_existing_content = false) 
    190     { 
    191         // Define globals 
    192         global $db; 
    193  
    194         // Init values 
    195         $content_group_element_object = null; 
    196         $max_display_order_row = null; 
    197  
    198         if($associate_existing_content == true) { 
    199             $name = "{$user_prefix}_add"; 
    200         } else { 
    201             $name = "get_new_content_{$user_prefix}_add"; 
    202         } 
    203  
    204         if (!empty ($_REQUEST[$name]) && $_REQUEST[$name] == true) { 
    205             /* Get the display order to add the GontentGroupElement at the end */ 
    206             $sql = "SELECT MAX(display_order) as max_display_order FROM content_group_element WHERE content_group_id='".$content_group->getId()."'"; 
    207             $db->execSqlUniqueRes($sql, $max_display_order_row, false); 
    208             $display_order = $max_display_order_row['max_display_order'] + 1; 
    209  
    210             if($associate_existing_content == true) { 
    211                 $name = "{$user_prefix}"; 
    212             } else { 
    213                 $name = "get_new_content_{$user_prefix}_content_type"; 
    214             } 
    215  
    216             $content_id = get_guid(); 
    217             $content_type = 'ContentGroupElement'; 
    218             $sql = "INSERT INTO content (content_id, content_type) VALUES ('$content_id', '$content_type');"; 
    219  
    220             if (!$db->execSqlUpdate($sql, false)) { 
    221                 throw new Exception(_('Unable to insert new content into database!')); 
    222             } 
    223  
    224             $sql = "INSERT INTO content_group_element (content_group_element_id, content_group_id, display_order) VALUES ('$content_id', '".$content_group->GetId()."', $display_order);"; 
    225  
    226             if (!$db->execSqlUpdate($sql, false)) { 
    227                 throw new Exception(_('Unable to insert new content into database!')); 
    228             } 
    229  
    230             $content_group_element_object = self :: getObject($content_id); 
    231  
    232             $content_ui_result = FormSelectGenerator :: getResult($name, null); 
    233  
    234             if($associate_existing_content == true) { 
    235                 $displayed_content_object = self :: getObject($content_ui_result); 
    236             } else { 
    237                 $displayed_content_object = self :: createNewObject($content_ui_result); 
    238             } 
    239  
    240             $content_group_element_object->replaceDisplayedContent($displayed_content_object); 
    241         } 
    242  
    243         return $content_group_element_object; 
    244     } 
    245     /** If set, content will only be displayed from this date on. */ 
    246     function getValidFromDate() 
    247     { 
    248         return $this->content_group_element_row['valid_from_timestamp']; 
    249     } 
    250  
    251     /** If set, content will only be displayed from this date on.  
    252      * @param string @date Start date.  To always display, set to null or an empty string */ 
    253     function setValidFromDate($date) 
    254     { 
    255         // Define globals 
    256         global $db; 
    257         if($date != $this->getValidFromDate()) 
    258         { 
    259         if(!empty($date)) 
    260         { 
    261         $date = "'".$db->escapeString($date)."'"; 
    262         } 
    263         else 
    264         { 
    265           $date = 'NULL';   
    266         } 
    267         $db->execSqlUpdate("UPDATE content_group_element SET valid_from_timestamp = {$date} WHERE content_group_element_id = '{$this->getId()}'"); 
    268         $this->refresh(); 
    269         } 
    270     } 
    271     /** If set, content will only be displayed untill this date (and will then be archived). */ 
    272     function getValidUntilDate() 
    273     { 
    274         return $this->content_group_element_row['valid_until_timestamp']; 
    275     } 
    276  
    277     /** If set, content will only be displayed untill this date (and will then be archived).  
    278      * @param string @date End date.  To always display, set to null or an empty string */ 
    279     function setValidUntilDate($date) 
    280     { 
    281         // Define globals 
    282         global $db; 
    283                 if($date != $this->getValidUntilDate()) 
    284         { 
    285         if(!empty($date)) 
    286         { 
    287         $date = "'".$db->escapeString($date)."'"; 
    288         } 
    289         else 
    290         { 
    291           $date = 'NULL';   
    292         } 
    293         $db->execSqlUpdate("UPDATE content_group_element SET valid_until_timestamp = {$date} WHERE content_group_element_id = '{$this->getId()}'"); 
    294         $this->refresh(); 
    295         } 
    296     } 
    297  
    298     /** 
    299      * Shows the administration interface for ContentGroupElement 
    300      * 
    301      * @param string $subclass_admin_interface HTML code to be added after the 
    302      *                                         administration interface 
    303      * 
    304      * @return string HTML code for the administration interface 
    305      */ 
    306     public function getAdminUI($subclass_admin_interface = null, $title=null) 
    307     { 
    308         // Define globals 
    309         global $db; 
    310  
    311         // Init values 
    312         $html = ''; 
    313         $html .= "<li class='admin_element_item_container'>\n"; 
    314         $html .= "<fieldset class='admin_element_group'>\n"; 
    315                 $html .= "<legend>". sprintf(_("%s %d display conditions"), get_class($this), $this->getDisplayOrder())."</legend>\n"; 
    316  
    317         $allowed_node_rows = null; 
     63class ContentGroupElement extends Content { 
     64 
     65        /** 
     66         
     67         */ 
     68        private $content_group_element_row; 
     69 
     70        /** 
     71         * Constructor 
     72         * 
     73         * @param string $content_id Content Id 
     74         * 
     75         * @return void     */ 
     76        protected function __construct($content_id) { 
     77                // Define globals 
     78                global $db; 
     79 
     80                // Init values 
     81                $row = null; 
     82 
     83                parent :: __construct($content_id); 
     84                $content_id = $db->escapeString($content_id); 
     85 
     86                $sql_select = "SELECT * FROM content_group_element WHERE content_group_element_id='$content_id'"; 
     87                $db->execSqlUniqueRes($sql_select, $row, false); 
     88 
     89                if ($row == null) { 
     90                        // The database was corrupted, let's fix it ... 
     91                        $sql = "DELETE FROM content WHERE content_id='$content_id'"; 
     92                        $db->execSqlUpdate($sql, true); 
     93                } 
     94 
     95                $this->content_group_element_row = $row; 
     96 
     97                /* A content group element is NEVER persistent */ 
     98                parent :: setIsPersistent(false); 
     99        } 
     100        /** When a content object is set as Simple, it means that is is used merely to contain it's own data.  No title, description or other metadata will be set or displayed, during display or administration 
     101         * @return true or false */ 
     102        public function isSimpleContent() { 
     103                return true; 
     104        } 
     105        /** 
     106         * Replace and delete the old displayed_content (if any) by the new 
     107         * content (or no content) 
     108         * 
     109         * @param object $new_displayed_content Content object or null. If 
     110         *                                      null the old content is still 
     111         *                                      deleted. 
     112         * 
     113         * @return void 
     114         
     115         */ 
     116        private function replaceDisplayedContent($new_displayed_content) { 
     117                // Define globals 
     118                global $db; 
     119 
     120                // Init values 
     121                $old_displayed_content = null; 
     122                $errmsg = null; 
     123 
     124                if (!empty ($this->content_group_element_row['displayed_content_id'])) { 
     125                        $old_displayed_content = self :: getObject($this->content_group_element_row['displayed_content_id']); 
     126                } 
     127 
     128                if ($new_displayed_content != null) { 
     129                        $new_displayed_content_id_sql = "'" . $new_displayed_content->GetId() . "'"; 
     130                } else { 
     131                        $new_displayed_content_id_sql = "NULL"; 
     132                } 
     133 
     134                $db->execSqlUpdate("UPDATE content_group_element SET displayed_content_id = $new_displayed_content_id_sql WHERE content_group_element_id = '$this->id'", FALSE); 
     135 
     136                if ($old_displayed_content != null) { 
     137                        $old_displayed_conten->delete($errmsg); 
     138                } 
     139        } 
     140 
     141        /** 
     142         * Get the order of the element in the content group 
     143         * 
     144         * @return string the order of the element in the content group 
     145         */ 
     146        public function getDisplayOrder() { 
     147                return $this->content_group_element_row['display_order']; 
     148        } 
     149 
     150        /** 
     151         * Set the order of the element in the content group 
     152         * 
     153         * @param string $order Order how items should be displayed 
     154         * 
     155         * @return void 
     156         */ 
     157        public function setDisplayOrder($order) { 
     158                // Define globals 
     159                global $db; 
     160 
     161                if ($order != $this->getDisplayOrder()) { 
     162                        /* 
     163                         * Only update database if there is an actual change 
     164                         */ 
     165                        $order = $db->escapeString($order); 
     166                        $db->execSqlUpdate("UPDATE content_group_element SET display_order = $order WHERE content_group_element_id = '$this->id'", false); 
     167                } 
     168        } 
     169 
     170        /** 
     171         * Like the same method as defined in Content, this method will create a 
     172         * ContentGroupElement based on the content type specified by 
     173         * getNewContentUI OR get an existing element by getSelectExistingContentUI 
     174         * 
     175         * @param string $user_prefix                A identifier provided by the programmer to 
     176         *                                           recognise it's generated form 
     177         * @param string $content_group              Must be present 
     178         * @param bool   $associate_existing_content If set to true, will get an 
     179         *                                           existing element instead of creating a 
     180         *                                           new content. 
     181         * 
     182         * @return object The ContentGroup object, or null if the user didn't greate one 
     183         * @static 
     184         */ 
     185        public static function processNewContentUI($user_prefix, ContentGroup $content_group, $associate_existing_content = false) { 
     186                // Define globals 
     187                global $db; 
     188 
     189                // Init values 
     190                $content_group_element_object = null; 
     191                $max_display_order_row = null; 
     192 
     193                if ($associate_existing_content == true) { 
     194                        $name = "{$user_prefix}_add"; 
     195                } else { 
     196                        $name = "get_new_content_{$user_prefix}_add"; 
     197                } 
     198 
     199                if (!empty ($_REQUEST[$name]) && $_REQUEST[$name] == true) { 
     200                        /* Get the display order to add the GontentGroupElement at the end */ 
     201                        $sql = "SELECT MAX(display_order) as max_display_order FROM content_group_element WHERE content_group_id='" . $content_group->getId() . "'"; 
     202                        $db->execSqlUniqueRes($sql, $max_display_order_row, false); 
     203                        $display_order = $max_display_order_row['max_display_order'] + 1; 
     204 
     205                        if ($associate_existing_content == true) { 
     206                                $name = "{$user_prefix}"; 
     207                        } else { 
     208                                $name = "get_new_content_{$user_prefix}_content_type"; 
     209                        } 
     210 
     211                        $content_id = get_guid(); 
     212                        $content_type = 'ContentGroupElement'; 
     213                        $sql = "INSERT INTO content (content_id, content_type) VALUES ('$content_id', '$content_type');"; 
     214 
     215                        if (!$db->execSqlUpdate($sql, false)) { 
     216                                throw new Exception(_('Unable to insert new content into database!')); 
     217                        } 
     218 
     219                        $sql = "INSERT INTO content_group_element (content_group_element_id, content_group_id, display_order) VALUES ('$content_id', '" . $content_group->GetId() . "', $display_order);"; 
     220 
     221                        if (!$db->execSqlUpdate($sql, false)) { 
     222                                throw new Exception(_('Unable to insert new content into database!')); 
     223                        } 
     224 
     225                        $content_group_element_object = self :: getObject($content_id); 
     226 
     227                        $content_ui_result = FormSelectGenerator :: getResult($name, null); 
     228 
     229                        if ($associate_existing_content == true) { 
     230                                $displayed_content_object = self :: getObject($content_ui_result); 
     231                        } else { 
     232                                $displayed_content_object = self :: createNewObject($content_ui_result); 
     233                        } 
     234 
     235                        $content_group_element_object->replaceDisplayedContent($displayed_content_object); 
     236                } 
     237 
     238                return $content_group_element_object; 
     239        } 
     240        /** If set, content will only be displayed from this date on. */ 
     241        function getValidFromDate() { 
     242                return $this->content_group_element_row['valid_from_timestamp']; 
     243        } 
     244 
     245        /** If set, content will only be displayed from this date on.  
     246         * @param string @date Start date.  To always display, set to null or an empty string */ 
     247        function setValidFromDate($date) { 
     248                // Define globals 
     249                global $db; 
     250                if ($date != $this->getValidFromDate()) { 
     251                        if (!empty ($date)) { 
     252                                $date = "'" . $db->escapeString($date) . "'"; 
     253                        } else { 
     254                                $date = 'NULL'; 
     255                        } 
     256                        $db->execSqlUpdate("UPDATE content_group_element SET valid_from_timestamp = {$date} WHERE content_group_element_id = '{$this->getId()}'"); 
     257                        $this->refresh(); 
     258                } 
     259        } 
     260        /** If set, content will only be displayed untill this date (and will then be archived). */ 
     261        function getValidUntilDate() { 
     262                return $this->content_group_element_row['valid_until_timestamp']; 
     263        } 
     264 
     265        /** If set, content will only be displayed untill this date (and will then be archived).  
     266         * @param string @date End date.  To always display, set to null or an empty string */ 
     267        function setValidUntilDate($date) { 
     268                // Define globals 
     269                global $db; 
     270                if ($date != $this->getValidUntilDate()) { 
     271                        if (!empty ($date)) { 
     272                                $date = "'" . $db->escapeString($date) . "'"; 
     273                        } else { 
     274                                $date = 'NULL'; 
     275                        } 
     276                        $db->execSqlUpdate("UPDATE content_group_element SET valid_until_timestamp = {$date} WHERE content_group_element_id = '{$this->getId()}'"); 
     277                        $this->refresh(); 
     278                } 
     279        } 
     280 
     281        /** 
     282         * Shows the administration interface for ContentGroupElement 
     283         * 
     284         * @param string $subclass_admin_interface HTML code to be added after the 
     285         *                                         administration interface 
     286         * 
     287         * @return string HTML code for the administration interface 
     288         */ 
     289        public function getAdminUI($subclass_admin_interface = null, $title = null) { 
     290                // Define globals 
     291                global $db; 
     292 
     293                // Init values 
     294                $html = ''; 
     295                $html .= "<li class='admin_element_item_container'>\n"; 
     296                $html .= "<fieldset class='admin_element_group'>\n"; 
     297                $html .= "<legend>" . sprintf(_("%s %d display conditions"), get_class($this), $this->getDisplayOrder()) . "</legend>\n"; 
     298 
     299                $allowed_node_rows = null; 
    318300                $html .= "<ul class='admin_element_list'>\n"; 
    319         /* display_order */ 
    320         $html .= "<li class='admin_element_item_container'>\n"; 
    321         $html .= "<div class='admin_element_label'>Display order: </div>\n"; 
    322         $html .= "<div class='admin_element_data'>\n"; 
    323         $name = "content_group_element_".$this->id."_display_order"; 
    324         $html .= "<input type='text' name='$name' value='".$this->getDisplayOrder()."' size='2'>\n"; 
    325         $html .= _("(Ignored if display type is random)")."\n"; 
    326         $html .= "</div>\n"; 
    327         $html .= "</li>\n"; 
    328          
    329         $html .= "<li class='admin_element_item_container'>\n";  
    330         // valid_from_timestamp 
    331         $html .= "<div class='admin_element_label'>"._("Only display from")."</div>\n"; 
    332         $html .= "<div class='admin_element_data'>\n";         
    333         $name = "content_group_element_".$this->id."_valid_from"; 
    334         $html .= DateTime::getSelectDateTimeUI(new DateTime($this->getValidFromDate()), $name, DateTime::INTERFACE_DATETIME_FIELD, null); 
    335         $html .= "</div>\n"; 
    336  
    337         // valid_until_timestamp 
    338         $html .= "<div class='admin_element_label'>until</div>\n"; 
    339         $html .= "<div class='admin_element_data'>\n"; 
    340         $name = "content_group_element_".$this->id."_valid_until"; 
    341         $html .= DateTime::getSelectDateTimeUI(new DateTime($this->getValidUntilDate()), $name, DateTime::INTERFACE_DATETIME_FIELD, null); 
    342         $html .= "</div>\n"; 
    343          
    344         $html .= _("(Content can be displayed at any date if no start or end date is specified.  Warning:  If you do not specify a specifig time of day, midnight is assumed.)")."\n"; 
    345         $html .= "</li>\n"; 
    346          
    347         /* content_group_element_has_allowed_nodes */ 
    348         $html .= "<li class='admin_element_item_container'>\n"; 
    349         $html .= "<div class='admin_element_label'>"._("Only display at node(s):")."</div>\n"; 
    350         $html .= "<ul class='admin_element_list'>\n"; 
    351  
    352         $sql = "SELECT * FROM content_group_element_has_allowed_nodes WHERE content_group_element_id='$this->id'"; 
    353         $db->execSql($sql, $allowed_node_rows, false); 
    354  
    355         if ($allowed_node_rows != null) { 
    356             foreach ($allowed_node_rows as $allowed_node_row) { 
    357                 $node = Node :: getObject($allowed_node_row['node_id']); 
    358                 $html .= "<li class='admin_element_item_container'>\n"; 
    359                 $html .= "<div class='admin_element_data'>\n"; 
    360                 $html .= "".$node->GetId().": ".$node->GetName().""; 
    361                 $html .= "</div>\n"; 
    362                 $html .= "<div class='admin_element_tools'>\n"; 
    363                 $name = "content_group_element_".$this->id."_allowed_node_".$node->GetId()."_remove"; 
    364                 $html .= "<input type='submit' name='$name' value='"._("Remove")."'>"; 
    365                 $html .= "</div>\n"; 
    366                 $html .= "</li>\n"; 
    367             } 
    368         } 
    369  
    370         $html .= "<li class='admin_element_item_container'>\n"; 
    371  
    372         $sql_additional_where = "AND node_id NOT IN (SELECT node_id FROM content_group_element_has_allowed_nodes WHERE content_group_element_id='$this->id')"; 
    373         $name = "content_group_element_{$this->id}_new_allowed_node"; 
    374         $html .= Node :: getSelectNodeUI($name, $sql_additional_where); 
    375         $name = "content_group_element_{$this->id}_new_allowed_node_submit"; 
    376         $html .= "<input type='submit' name='$name' value='"._("Add new allowed node")."'>"; 
    377         $html .= "</li'>\n"; 
    378         $html .= "</ul>\n"; 
    379         $html .= _("(Content can be displayed at ANY node unless one or more nodes are selected)")."\n"; 
    380  
    381         $html .= "</li>\n"; 
    382         $html .= "</fieldset>\n"; 
    383         $html .= "</li>\n"; 
    384  
    385         /* displayed_content_id */ 
    386         $html .= "<li class='admin_element_item_container'>\n"; 
    387         if (empty ($this->content_group_element_row['displayed_content_id'])) { 
    388           $html .= "<div class='errormsg'>Sorry, display element is missing.</div>\n"; 
    389 /*              $html .= "<fieldset class='admin_element_group'>\n"; 
    390                         $html .= "<legend>"._("Add a new displayed content OR select an existing one")."</legend>\n"; 
    391             $html .= self :: getNewContentUI("content_group_element_{$this->id}_new_displayed_content")."<br>"; 
    392             $html .= self :: getSelectExistingContentUI("content_group_element_{$this->id}_new_displayed_existing_element", "AND content_id != '$this->id'"); 
    393                         $html .= "</fieldset>\n";*/ 
    394         } else { 
    395             $displayed_content = self :: getObject($this->content_group_element_row['displayed_content_id']); 
    396             $html .= $displayed_content->getAdminUI(null, sprintf(_("%s %d displayed content (%s)"), get_class($this), $this->getDisplayOrder(), get_class($displayed_content))); 
    397             /*$html .= "<div class='admin_element_tools'>\n"; 
    398             $name = "content_group_element_{$this->id}_erase_displayed_content"; 
    399             $html .= "<input type='submit' name='$name' value='"._("Delete")."'>"; 
    400             $html .= "</div>\n";*/ 
    401         } 
    402         $html .= "</li>\n"; 
    403  
    404         $html .= $subclass_admin_interface; 
    405  
    406         return parent :: getAdminUI($html, $title); 
    407     } 
    408  
    409     /** 
    410      * Processes the input of the administration interface for ContentGroupElement 
    411      * 
    412      * @return void 
    413      */ 
    414     public function processAdminUI() 
    415     { 
    416         // Define globals 
    417         global $db; 
    418  
    419         // Init values 
    420         $allowed_node_rows = null; 
    421         $errmsg = null; 
    422  
    423         parent::processAdminUI(); 
    424  
    425         /* display_order */ 
    426         $name = "content_group_element_".$this->id."_display_order"; 
    427         $this->setDisplayOrder($_REQUEST[$name]); 
    428  
    429         // valid_from_timestamp 
    430         $name = "content_group_element_".$this->id."_valid_from"; 
    431         $this->setValidFromDate(DateTime::processSelectDateTimeUI($name, DateTime :: INTERFACE_DATETIME_FIELD)->getIso8601FormattedString()); 
    432  
    433         // valid_until_timestamp 
    434  
    435         $name = "content_group_element_".$this->id."_valid_until"; 
    436         $this->setValidUntilDate(DateTime::processSelectDateTimeUI($name, DateTime :: INTERFACE_DATETIME_FIELD)->getIso8601FormattedString()); 
    437  
    438         /* content_group_element_has_allowed_nodes */ 
    439         $sql = "SELECT * FROM content_group_element_has_allowed_nodes WHERE content_group_element_id='$this->id'"; 
    440         $db->execSql($sql, $allowed_node_rows, false); 
    441  
    442         if ($allowed_node_rows != null) { 
    443             foreach ($allowed_node_rows as $allowed_node_row) { 
    444                 $node = Node :: getObject($allowed_node_row['node_id']); 
    445                 $name = "content_group_element_".$this->id."_allowed_node_".$node->GetId()."_remove"; 
    446  
    447                 if (!empty ($_REQUEST[$name]) && $_REQUEST[$name] == true) { 
    448                     $sql = "DELETE FROM content_group_element_has_allowed_nodes WHERE content_group_element_id='$this->id' AND node_id='".$node->GetId()."'"; 
    449                     $db->execSqlUpdate($sql, false); 
    450                 } 
    451             } 
    452         } 
    453  
    454         $name = "content_group_element_{$this->id}_new_allowed_node_submit"; 
    455  
    456         if (!empty ($_REQUEST[$name]) && $_REQUEST[$name] == true) { 
    457             $name = "content_group_element_{$this->id}_new_allowed_node"; 
    458             $node = Node :: processSelectNodeUI($name); 
    459             $node_id = $node->GetId(); 
    460             $db->execSqlUpdate("INSERT INTO content_group_element_has_allowed_nodes (content_group_element_id, node_id) VALUES ('$this->id', '$node_id')", FALSE); 
    461         } 
    462  
    463         /* displayed_content_id */ 
    464         if (empty ($this->content_group_element_row['displayed_content_id'])) { 
    465             // Could be either a new content or existing content ( try both successively ) 
    466             $displayed_content = Content :: processNewContentUI("content_group_element_{$this->id}_new_displayed_content"); 
    467  
    468             if ($displayed_content == null) { 
    469                 $displayed_content = Content :: processNewContentUI("content_group_element_{$this->id}_new_displayed_existing_element", true); 
    470             } 
    471  
    472             if ($displayed_content != null) { 
    473                 $displayed_content_id = $displayed_content->GetId(); 
    474                 $db->execSqlUpdate("UPDATE content_group_element SET displayed_content_id = '$displayed_content_id' WHERE content_group_element_id = '$this->id'", FALSE); 
    475                 $displayed_content->setIsPersistent(false); 
    476             } 
    477         } else { 
    478             $displayed_content = self::getObject($this->content_group_element_row['displayed_content_id']); 
    479             $name = "content_group_element_{$this->id}_erase_displayed_content"; 
    480  
    481             if (!empty ($_REQUEST[$name]) && $_REQUEST[$name] == true) { 
    482                 if($displayed_content->delete($errmsg) != false) { 
    483                     $db->execSqlUpdate("UPDATE content_group_element SET displayed_content_id = NULL WHERE content_group_element_id = '$this->id'", FALSE); 
    484                 } else { 
    485                     echo $errmsg; 
    486                 } 
    487             } else { 
    488                 $displayed_content->processAdminUI(); 
    489             } 
    490         } 
    491     } 
    492  
    493     /** 
    494      * Retreives the user interface of this object. 
    495      * 
    496      * @return string The HTML fragment for this interface 
    497      */ 
    498     public function getUserUI($subclass_user_interface = null) 
    499     { 
    500         // Init values 
    501         $html = ''; 
    502  
    503         if (!empty ($this->content_group_element_row['displayed_content_id'])) { 
    504             $displayed_content = self::getObject($this->content_group_element_row['displayed_content_id']); 
    505  
    506             // If the content group logging is disabled, all the children will inherit this property temporarly 
    507             if($this->getLoggingStatus() == false) { 
    508                 $displayed_content->setLoggingStatus(false); 
    509             } 
    510  
    511             $displayed_content_html = $displayed_content->getUserUI(); 
    512         } 
    513  
    514         $html .= "<div class='user_ui_container ".get_class($this)."'>\n"; 
    515         $html .= $displayed_content_html; 
    516         $html .= $subclass_user_interface; 
    517         $html .= "</div>\n"; 
    518  
    519         return parent :: getUserUI($html); 
    520     } 
    521  
    522     /** 
    523      * Returns if this this Content element is displayable at this hotspot 
    524      * 
    525      * @param string $node Node Id 
    526      * 
    527      * @return bool True if it is displayable 
    528      */ 
    529     public function isDisplayableAt($node) 
    530     { 
    531         // Define globals 
    532         global $db; 
    533  
    534         // Init values 
    535         $retval = false; 
    536         $allowed_node_rows = null; 
    537  
    538         $sql = "SELECT * FROM content_group_element_has_allowed_nodes WHERE content_group_element_id='$this->id'"; 
    539         $db->execSql($sql, $allowed_node_rows, false); 
    540  
    541         if ($allowed_node_rows != null) { 
    542             if ($node) { 
    543                 $node_id = $node->getId(); 
    544                 /** 
    545                  * @todo  Proper algorithm, this is a dirty and slow hack 
    546                  */ 
    547                 foreach ($allowed_node_rows as $allowed_node_row) { 
    548                     if ($allowed_node_row['node_id'] == $node_id) { 
    549                         $retval = true; 
    550                     } 
    551                 } 
    552             } else { 
    553                 /* There are allowed nodes, but we don't know at which node we want to display */ 
    554                 $retval = false; 
    555             } 
    556         } else { 
    557             /* No allowed node means all nodes are allowed */ 
    558             $retval = true; 
    559         } 
    560  
    561         return $retval; 
    562     } 
    563  
    564     /** 
    565      * Detects if a user is owner of a ContentGroupElement 
    566      * 
    567      * Override the method in Content. 
    568      * 
    569      * The owners of the content element are always considered to be the ContentGroup's 
    570      * 
    571      * @param object $user User object: the user to be tested. 
    572      * 
    573      * @return bool True if the user is a owner, false if he isn't or if the user is null 
    574      */ 
    575     public function isOwner($user) 
    576     { 
    577         $content_group = Content :: getObject($this->content_group_element_row['content_group_id']); 
    578         return $content_group->isOwner($user); 
    579     } 
    580  
    581     /** 
    582      * Deletes a ContentGroupElement object 
    583      * 
    584      * @param string $errmsg Reference to error message 
    585      * 
    586      * @return bool True if deletion was successful 
    587      * @internal Persistent content will not be deleted 
    588      * 
    589      * @todo Implement proper access control 
    590      */ 
    591     public function delete(& $errmsg) 
    592     { 
    593         if ($this->isPersistent() == false && !empty ($this->content_group_element_row['displayed_content_id'])) { 
    594             $displayed_content = self::getObject($this->content_group_element_row['displayed_content_id']); 
    595             $displayed_content->delete($errmsg); 
    596             parent::delete($errmsg); 
    597         } 
    598     } 
    599         /** Reloads the object from the database.  Should normally be called after a set operation */ 
    600     protected function refresh() 
    601     { 
    602         $this->__construct($this->id); 
    603     } 
     301                /* display_order */ 
     302                $html .= "<li class='admin_element_item_container'>\n"; 
     303                $html .= "<div class='admin_element_label'>Display order: </div>\n"; 
     304                $html .= "<div class='admin_element_data'>\n"; 
     305                $name = "content_group_element_" . $this->id . "_display_order"; 
     306                $html .= "<input type='text' name='$name' value='" . $this->getDisplayOrder() . "' size='2'>\n"; 
     307                $html .= _("(Ignored if display type is random)") . "\n"; 
     308                $html .= "</div>\n"; 
     309                $html .= "</li>\n"; 
     310 
     311                $html .= "<li class='admin_element_item_container'>\n"; 
     312                // valid_from_timestamp 
     313                $html .= "<div class='admin_element_label'>" . _("Only display from") . "</div>\n"; 
     314                $html .= "<div class='admin_element_data'>\n"; 
     315                $name = "content_group_element_" . $this->id . "_valid_from"; 
     316                $html .= DateTime :: getSelectDateTimeUI(new DateTime($this->getValidFromDate()), $name, DateTime :: INTERFACE_DATETIME_FIELD, null); 
     317                $html .= "</div>\n"; 
     318 
     319                // valid_until_timestamp 
     320                $html .= "<div class='admin_element_label'>until</div>\n"; 
     321                $html .= "<div class='admin_element_data'>\n"; 
     322                $name = "content_group_element_" . $this->id . "_valid_until"; 
     323                $html .= DateTime :: getSelectDateTimeUI(new DateTime($this->getValidUntilDate()), $name, DateTime :: INTERFACE_DATETIME_FIELD, null); 
     324                $html .= "</div>\n"; 
     325 
     326                $html .= _("(Content can be displayed at any date if no start or end date is specified.  Warning:  If you do not specify a specifig time of day, midnight is assumed.)") . "\n"; 
     327                $html .= "</li>\n"; 
     328 
     329                /* content_group_element_has_allowed_nodes */ 
     330                $html .= "<li class='admin_element_item_container'>\n"; 
     331                $html .= "<div class='admin_element_label'>" . _("Only display at node(s):") . "</div>\n"; 
     332                $html .= "<ul class='admin_element_list'>\n"; 
     333 
     334                $sql = "SELECT * FROM content_group_element_has_allowed_nodes WHERE content_group_element_id='$this->id'"; 
     335                $db->execSql($sql, $allowed_node_rows, false); 
     336 
     337                if ($allowed_node_rows != null) { 
     338                        foreach ($allowed_node_rows as $allowed_node_row) { 
     339                                $node = Node :: getObject($allowed_node_row['node_id']); 
     340                                $html .= "<li class='admin_element_item_container'>\n"; 
     341                                $html .= "<div class='admin_element_data'>\n"; 
     342                                $html .= "" . $node->GetId() . ": " . $node->GetName() . ""; 
     343                                $html .= "</div>\n"; 
     344                                $html .= "<div class='admin_element_tools'>\n"; 
     345                                $name = "content_group_element_" . $this->id . "_allowed_node_" . $node->GetId() . "_remove"; 
     346                                $html .= "<input type='submit' name='$name' value='" . _("Remove") . "'>"; 
     347                                $html .= "</div>\n"; 
     348                                $html .= "</li>\n"; 
     349                        } 
     350                } 
     351 
     352                $html .= "<li class='admin_element_item_container'>\n"; 
     353 
     354                $sql_additional_where = "AND node_id NOT IN (SELECT node_id FROM content_group_element_has_allowed_nodes WHERE content_group_element_id='$this->id')"; 
     355                $name = "content_group_element_{$this->id}_new_allowed_node"; 
     356                $html .= Node :: getSelectNodeUI($name, $sql_additional_where); 
     357                $name = "content_group_element_{$this->id}_new_allowed_node_submit"; 
     358                $html .= "<input type='submit' name='$name' value='" . _("Add new allowed node") . "'>"; 
     359                $html .= "</li'>\n"; 
     360                $html .= "</ul>\n"; 
     361                $html .= _("(Content can be displayed at ANY node unless one or more nodes are selected)") . "\n"; 
     362 
     363                $html .= "</li>\n"; 
     364                $html .= "</fieldset>\n"; 
     365                $html .= "</li>\n"; 
     366 
     367                /* displayed_content_id */ 
     368                $html .= "<li class='admin_element_item_container'>\n"; 
     369                if (empty ($this->content_group_element_row['displayed_content_id'])) { 
     370                        $html .= "<div class='errormsg'>Sorry, display element is missing.</div>\n"; 
     371                        /*              $html .= "<fieldset class='admin_element_group'>\n"; 
     372                                                $html .= "<legend>"._("Add a new displayed content OR select an existing one")."</legend>\n"; 
     373                                    $html .= self :: getNewContentUI("content_group_element_{$this->id}_new_displayed_content")."<br>"; 
     374                                    $html .= self :: getSelectExistingContentUI("content_group_element_{$this->id}_new_displayed_existing_element", "AND content_id != '$this->id'"); 
     375                                                $html .= "</fieldset>\n";*/ 
     376                } else { 
     377                        $displayed_content = self :: getObject($this->content_group_element_row['displayed_content_id']); 
     378                        $html .= $displayed_content->getAdminUI(null, sprintf(_("%s %d displayed content (%s)"), get_class($this), $this->getDisplayOrder(), get_class($displayed_content))); 
     379                        /*$html .= "<div class='admin_element_tools'>\n"; 
     380                        $name = "content_group_element_{$this->id}_erase_displayed_content"; 
     381                        $html .= "<input type='submit' name='$name' value='"._("Delete")."'>"; 
     382                        $html .= "</div>\n";*/ 
     383                } 
     384                $html .= "</li>\n"; 
     385 
     386                $html .= $subclass_admin_interface; 
     387 
     388                return parent :: getAdminUI($html, $title); 
     389        } 
     390 
     391        /** 
     392         * Processes the input of the administration interface for ContentGroupElement 
     393         * 
     394         * @return void 
     395         */ 
     396        public function processAdminUI() { 
     397                // Define globals 
     398                global $db; 
     399 
     400                // Init values 
     401                $allowed_node_rows = null; 
     402                $errmsg = null; 
     403 
     404                parent :: processAdminUI(); 
     405 
     406                /* display_order */ 
     407                $name = "content_group_element_" . $this->id . "_display_order"; 
     408                $this->setDisplayOrder($_REQUEST[$name]); 
     409 
     410                // valid_from_timestamp 
     411                $name = "content_group_element_" . $this->id . "_valid_from"; 
     412                $this->setValidFromDate(DateTime :: processSelectDateTimeUI($name, DateTime :: INTERFACE_DATETIME_FIELD)->getIso8601FormattedString()); 
     413 
     414                // valid_until_timestamp 
     415 
     416                $name = "content_group_element_" . $this->id . "_valid_until"; 
     417                $this->setValidUntilDate(DateTime :: processSelectDateTimeUI($name, DateTime :: INTERFACE_DATETIME_FIELD)->getIso8601FormattedString()); 
     418 
     419                /* content_group_element_has_allowed_nodes */ 
     420                $sql = "SELECT * FROM content_group_element_has_allowed_nodes WHERE content_group_element_id='$this->id'"; 
     421                $db->execSql($sql, $allowed_node_rows, false); 
     422 
     423                if ($allowed_node_rows != null) { 
     424                        foreach ($allowed_node_rows as $allowed_node_row) { 
     425                                $node = Node :: getObject($allowed_node_row['node_id']); 
     426                                $name = "content_group_element_" . $this->id . "_allowed_node_" . $node->GetId() . "_remove"; 
     427 
     428                                if (!empty ($_REQUEST[$name]) && $_REQUEST[$name] == true) { 
     429                                        $sql = "DELETE FROM content_group_element_has_allowed_nodes WHERE content_group_element_id='$this->id' AND node_id='" . $node->GetId() . "'"; 
     430                                        $db->execSqlUpdate($sql, false); 
     431                                } 
     432                        } 
     433                } 
     434 
     435                $name = "content_group_element_{$this->id}_new_allowed_node_submit"; 
     436 
     437                if (!empty ($_REQUEST[$name]) && $_REQUEST[$name] == true) { 
     438                        $name = "content_group_element_{$this->id}_new_allowed_node"; 
     439                        $node = Node :: processSelectNodeUI($name); 
     440                        $node_id = $node->GetId(); 
     441                        $db->execSqlUpdate("INSERT INTO content_group_element_has_allowed_nodes (content_group_element_id, node_id) VALUES ('$this->id', '$node_id')", FALSE); 
     442                } 
     443 
     444                /* displayed_content_id */ 
     445                if (empty ($this->content_group_element_row['displayed_content_id'])) { 
     446                        // Could be either a new content or existing content ( try both successively ) 
     447                        $displayed_content = Content :: processNewContentUI("content_group_element_{$this->id}_new_displayed_content"); 
     448 
     449                        if ($displayed_content == null) { 
     450                                $displayed_content = Content :: processNewContentUI("content_group_element_{$this->id}_new_displayed_existing_element", true); 
     451                        } 
     452 
     453                        if ($displayed_content != null) { 
     454                                $displayed_content_id = $displayed_content->GetId(); 
     455                                $db->execSqlUpdate("UPDATE content_group_element SET displayed_content_id = '$displayed_content_id' WHERE content_group_element_id = '$this->id'", FALSE); 
     456                                $displayed_content->setIsPersistent(false); 
     457                        } 
     458                } else { 
     459                        $displayed_content = self :: getObject($this->content_group_element_row['displayed_content_id']); 
     460                        $name = "content_group_element_{$this->id}_erase_displayed_content"; 
     461 
     462                        if (!empty ($_REQUEST[$name]) && $_REQUEST[$name] == true) { 
     463                                if ($displayed_content->delete($errmsg) != false) { 
     464                                        $db->execSqlUpdate("UPDATE content_group_element SET displayed_content_id = NULL WHERE content_group_element_id = '$this->id'", FALSE); 
     465                                } else { 
     466                                        echo $errmsg; 
     467                                } 
     468                        } else { 
     469                                $displayed_content->processAdminUI(); 
     470                        } 
     471                } 
     472        } 
     473 
     474        /** 
     475         * Retreives the user interface of this object. 
     476         * 
     477         * @return string The HTML fragment for this interface 
     478         */ 
     479        public function getUserUI($subclass_user_interface = null) { 
     480                // Init values 
     481                $html = ''; 
     482 
     483                if (!empty ($this->content_group_element_row['displayed_content_id'])) { 
     484                        $displayed_content = self :: getObject($this->content_group_element_row['displayed_content_id']); 
     485 
     486                        // If the content group logging is disabled, all the children will inherit this property temporarly 
     487                        if ($this->getLoggingStatus() == false) { 
     488                                $displayed_content->setLoggingStatus(false); 
     489                        } 
     490 
     491                        $displayed_content_html = $displayed_content->getUserUI(); 
     492                } 
     493 
     494                $html .= "<div class='user_ui_container " . get_class($this) . "'>\n"; 
     495                $html .= $displayed_content_html; 
     496                $html .= $subclass_user_interface; 
     497                $html .= "</div>\n"; 
     498 
     499                return parent :: getUserUI($html); 
     500        } 
     501 
     502        /** 
     503         * Returns if this this Content element is displayable at this hotspot 
     504         * 
     505         * @param string $node Node Id 
     506         * 
     507         * @return bool True if it is displayable 
     508         */ 
     509        public function isDisplayableAt($node) { 
     510                // Define globals 
     511                global $db; 
     512 
     513                // Init values 
     514                $retval = false; 
     515                $allowed_node_rows = null; 
     516 
     517                $sql = "SELECT * FROM content_group_element_has_allowed_nodes WHERE content_group_element_id='$this->id'"; 
     518                $db->execSql($sql, $allowed_node_rows, false); 
     519 
     520                if ($allowed_node_rows != null) { 
     521                        if ($node) { 
     522                                $node_id = $node->getId(); 
     523                                /** 
     524                                 * @todo  Proper algorithm, this is a dirty and slow hack 
     525                                 */ 
     526                                foreach ($allowed_node_rows as $allowed_node_row) { 
     527                                        if ($allowed_node_row['node_id'] == $node_id) { 
     528                                                $retval = true; 
     529                                        } 
     530                                } 
     531                        } else { 
     532                                /* There are allowed nodes, but we don't know at which node we want to display */ 
     533                                $retval = false; 
     534                        } 
     535                } else { 
     536                        /* No allowed node means all nodes are allowed */ 
     537                        $retval = true; 
     538                } 
     539 
     540                return $retval; 
     541        } 
     542 
     543        /** 
     544         * Detects if a user is owner of a ContentGroupElement 
     545         * 
     546         * Override the method in Content. 
     547         * 
     548         * The owners of the content element are always considered to be the ContentGroup's 
     549         * 
     550         * @param object $user User object: the user to be tested. 
     551         * 
     552         * @return bool True if the user is a owner, false if he isn't or if the user is null 
     553         */ 
     554        public function isOwner($user) { 
     555                $content_group = Content :: getObject($this->content_group_element_row['content_group_id']); 
     556                return $content_group->isOwner($user); 
     557        } 
     558 
     559        /** 
     560         * Deletes a ContentGroupElement object 
     561         * 
     562         * @param string $errmsg Reference to error message 
     563         * 
     564         * @return bool True if deletion was successful 
     565         * @internal Persistent content will not be deleted 
     566         * 
     567         * @todo Implement proper access control 
     568         */ 
     569        public function delete(& $errmsg) { 
     570                if ($this->isPersistent() == false && !empty ($this->content_group_element_row['displayed_content_id'])) { 
     571                        $displayed_content = self :: getObject($this->content_group_element_row['displayed_content_id']); 
     572                        $displayed_content->delete($errmsg); 
     573                        parent :: delete($errmsg); 
     574                } 
     575        } 
     576        /** Reloads the object from the database.  Should normally be called after a set operation */ 
     577        protected function refresh() { 
     578                $this->__construct($this->id); 
     579        } 
    604580} 
    605581 
     
    611587 * End: 
    612588 */ 
    613  
    614  
  • trunk/wifidog-auth/wifidog/classes/HyperLink.php

    r1080 r1091  
    4747 * Load required classes 
    4848 */ 
    49 require_once('classes/User.php'); 
     49require_once ('classes/User.php'); 
    5050 
    5151/** 
     
    5757 */ 
    5858class HyperLink { 
     59    const pattern = '/(<a\s.*?HREF=[\'"]?)((?:http|https|ftp).*?)([\'"\s].*?>)/mi'; 
     60 
    5961    /** 
    6062     * Find http, https and ftp hyperlinks in a string 
     
    6567     
    6668     */ 
    67     public static function findHyperLinks(&$string) { 
    68         $pattern = '/<a\s.*?HREF=[\'"]?((?:http|https|ftp).*?)[\'"\s].*?>/mi'; 
    69         //pretty_print_r($pattern); 
     69    private static function findHyperLinks(& $string) { 
     70        //pretty_print_r(self::pattern); 
    7071        $matches = null; 
    71         $num_matches = preg_match_all($pattern, $string, $matches); 
    72         //pretty_print_r($matches); 
    73         return $matches[1]; 
     72        $num_matches = preg_match_all(self :: pattern, $string, $matches); 
     73 
     74        return $matches; 
    7475    } 
    7576 
    76 /** Get the  clickthrough-logged equivalent of a sincle URL (http, https or ftp) */ 
    77     public static function getClickThroughLink($hyperlink, Content &$content, $node, $user) { 
    78         $node?$node_id=urlencode($node->getId()):$node_id=null; 
    79         $user?$user_id=urlencode($user->getId()):$user_id=null; 
    80         return BASE_URL_PATH . "clickthrough.php?destination_url=" . urlencode($hyperlink) . "&content_id=".urlencode($content->getId())."&node_id={$node_id}&user_id={$user_id}"; 
     77    /** Get the  clickthrough-logged equivalent of a sincle URL (http, https or ftp) */ 
     78    private static function getClickThroughLink($hyperlink, Content & $content, $node, $user) { 
     79        $node ? $node_id = urlencode($node->getId()) : $node_id = null; 
     80        $user ? $user_id = urlencode($user->getId()) : $user_id = null; 
     81        return BASE_URL_PATH . "clickthrough.php?destination_url=" . urlencode($hyperlink) . "&content_id=" . urlencode($content->getId()) . "&node_id={$node_id}&user_id={$user_id}"; 
    8182    } 
    8283 
    83 /** Replace all hyperlinks in the source string with their clickthrough-logged equivalents */ 
    84     public static function replaceHyperLinks(&$string, Content &$content) { 
    85         $links = self :: findHyperLinks($string); 
    86         if(!empty($links)) 
    87         { 
    88             $node = Node::getCurrentNode(); 
    89         $user = User::getCurrentUser(); 
    90         foreach ($links as $link) { 
    91             $replacements[] = self :: getClickThroughLink($link, $content, $node, $user); 
    92         } 
    93         //pretty_print_r($replacements); 
    94         return str_replace($links, $replacements, $string); 
    95         } 
    96         else 
    97         { 
     84    /** Replace all hyperlinks in the source string with their clickthrough-logged equivalents */ 
     85    public static function replaceHyperLinks(& $string, Content & $content) { 
     86        $matches = self :: findHyperLinks($string); 
     87        //pretty_print_r($matches); 
     88        if (!empty ($matches[2])) { 
     89            $node = Node :: getCurrentNode(); 
     90            $user = User :: getCurrentUser(); 
     91            $i = 0; 
     92            foreach ($matches[2] as $link) { 
     93                $new_link = self :: getClickThroughLink($link, $content, $node, $user); 
     94                $replacements[] = $matches[1][$i] . $new_link . $matches[3][$i]; 
     95                $i++; 
     96            } 
     97            //pretty_print_r($replacements); 
     98            return str_replace($matches[0], $replacements, $string); 
     99        } else { 
    98100            return $string; 
    99101        } 
  • trunk/wifidog-auth/wifidog/classes/Network.php

    r1090 r1091  
    5454require_once('classes/Cache.php'); 
    5555require_once('classes/ThemePack.php'); 
    56 require_once('classes/InterfaceElements.php'); 
    57 require_once('classes/MainUI.php'); 
     56 
    5857 
    5958/** 
     
    14911490    public function getAdminUI() 
    14921491    { 
     1492        require_once('classes/InterfaceElements.php'); 
    14931493        // Init values 
    14941494        $html = ''; 
     
    16951695        $user = User::getCurrentUser(); 
    16961696 
    1697         try { 
    16981697            if (!$this->hasAdminAccess($user)) { 
    16991698                throw new Exception(_('Access denied!')); 
    17001699            } 
    1701         } catch (Exception $e) { 
    1702             $ui = new MainUI(); 
    1703             $ui->setToolSection('ADMIN'); 
    1704             $ui->displayError($e->getMessage(), false); 
    1705             exit; 
    1706         } 
    1707  
     1700             
    17081701        // Content management 
    17091702        $name = "network_".$this->id."_content"; 
  • trunk/wifidog-auth/wifidog/classes/Node.php

    r1090 r1091  
    5050require_once('classes/Utils.php'); 
    5151require_once('classes/DateTime.php'); 
    52 require_once('classes/InterfaceElements.php'); 
    53 require_once('classes/MainUI.php'); 
    5452 
    5553/** 
     
    230228                $node_name = _("New node"); 
    231229 
    232                 try { 
    233230            if (Node::nodeExists($node_id)) { 
    234231                throw new Exception(_('This node already exists.')); 
     
    244241 
    245242            return $object; 
    246         } catch (Exception $e) { 
    247             $ui = new MainUI(); 
    248             $ui->setToolSection('ADMIN'); 
    249             $ui->displayError($e->getMessage(), false); 
    250             exit; 
    251         } 
    252243        } 
    253244 
     
    815806        public function getAdminUI() 
    816807        { 
     808            require_once('classes/InterfaceElements.php'); 
    817809            // Init values 
    818810                $html = ''; 
    819  
    820                 try { 
    821811                if (!User::getCurrentUser()) { 
    822812                        throw new Exception(_('Access denied!')); 
    823813                } 
    824         } catch (Exception $e) { 
    825             $ui = new MainUI(); 
    826             $ui->setToolSection('ADMIN'); 
    827             $ui->displayError($e->getMessage(), false); 
    828             exit; 
    829         } 
    830814 
    831815                // Get information about the network 
     
    10761060                $user = User::getCurrentUser(); 
    10771061 
    1078                 try { 
    10791062                if (!$this->isOwner($user) && !$user->isSuperAdmin()) { 
    10801063                        throw new Exception(_('Access denied!')); 
    10811064                } 
    1082         } catch (Exception $e) { 
    1083             $ui = new MainUI(); 
    1084             $ui->setToolSection('ADMIN'); 
    1085             $ui->displayError($e->getMessage(), false); 
    1086             exit; 
    1087         } 
     1065 
    10881066 
    10891067                // Check if user is a admin 
  • trunk/wifidog-auth/wifidog/classes/Server.php

    r1090 r1091  
    392392 
    393393                        if ($_serverId) { 
    394                             try { 
    395394                                if (!User::getCurrentUser()->isSuperAdmin()) { 
    396395                                        throw new Exception(_("Access denied")); 
    397396                                } 
    398                 } catch (Exception $e) { 
    399                     require_once('classes/MainUI.php'); 
    400  
    401                     $ui = new MainUI(); 
    402                     $ui->setToolSection('ADMIN'); 
    403                     $ui->displayError($e->getMessage(), false); 
    404                     exit; 
    405                 } 
     397 
    406398 
    407399                                $_retVal = self::createNewObject($_serverId); 
  • trunk/wifidog-auth/wifidog/classes/Statistics.php

    r1089 r1091  
    4747 */ 
    4848require_once('include/common.php'); 
    49 require_once('classes/MainUI.php'); 
    5049 
    5150/** 
     
    393392        $user = User::getCurrentUser(); 
    394393 
    395         try { 
    396394            if (!isset($user)) { 
    397395                throw new Exception(_('Access denied!')); 
     
    428426 
    429427            $html .= "</select>\n"; 
    430         } catch (Exception $e) { 
    431             $ui = new MainUI(); 
    432             $ui->setToolSection('ADMIN'); 
    433             $ui->displayError($e->getMessage(), false); 
    434             exit; 
    435         } 
     428 
    436429 
    437430        return $html; 
  • trunk/wifidog-auth/wifidog/classes/ThemePack.php

    r1090 r1091  
    3838 * @author     Benoit Grégoire <bock@step.polymtl.ca> 
    3939 * @copyright  2006 Benoit Grégoire, Technologies Coeus inc. 
    40  * @version    Subversion $Id: MainUI.php 1030 2006-05-09 20:01:17Z benoitg $ 
     40 * @version    Subversion $Id: $ 
    4141 * @link       http://www.wifidog.org/ 
    4242 */ 
  • trunk/wifidog-auth/wifidog/include/common_interface.php

    r946 r1091  
    5959 */ 
    6060require_once('classes/Session.php'); 
    61 require_once('classes/Statistics.php'); 
    6261require_once('classes/SmartyWifidog.php'); 
    6362require_once('classes/User.php'); 
    6463 
    6564$session = new Session(); 
    66 $stats = new Statistics(); 
    6765$smarty = new SmartyWifidog; 
    6866