Changeset 2292

Show
Ignore:
Timestamp:
12/11/10 07:22:57 (18 months ago)
Author:
petsagouris
Message:

[Branch 1.5] General Code Care, please update your WC's so that we all get the same source.

Location:
branches/1.5
Files:
16 modified

Legend:

Unmodified
Added
Removed
  • branches/1.5/hotaru_settings_default.php

    r2237 r2292  
    11<?php 
    2 /* Configuration file for Hotaru CMS�@*/ 
     2/* Configuration file for Hotaru CMS */ 
    33 
    44// Paths 
     
    66 
    77// Database details 
    8 define("DB_USER", 'root');                                              // Add your own database details  
     8define("DB_USER", 'root');                                              // Add your own database details 
    99define("DB_PASSWORD", ''); 
    1010define("DB_NAME", 'hotaru'); 
     
    1717define('DB_CHARSET', 'utf8');                                   // Database Character Set (UTF8 is Recommended), e.g. "utf8" 
    1818define("DB_COLLATE", 'utf8_unicode_ci');                // Database Collation (UTF8 is Recommended), e.g. "utf8_unicode_ci" 
    19  
    20 ?> 
  • branches/1.5/index.php

    r2238 r2292  
    2424 * @link      http://www.hotarucms.org/ 
    2525 */ 
    26 // includes 
     26 
    2727if( file_exists('hotaru_settings.php') ) { 
    2828        require_once('hotaru_settings.php'); 
     
    3838        } 
    3939} 
    40 ?> 
  • branches/1.5/libs/AdminPages.php

    r2267 r2292  
    2626class AdminPages 
    2727{ 
    28          /** 
     28 
     29        /** 
    2930         * Admin Pages 
    3031         */ 
     
    3233        { 
    3334                $h->vars['admin_sidebar_layout'] = 'vertical'; 
    34                  
     35 
    3536                $h->pluginHook('admin_pages'); 
    36                  
     37 
    3738                switch ($page) { 
    38                         case "admin_login": 
     39                        case 'admin_login': 
    3940                                $h->sidebars = false; 
    4041                                $h->adminLoginLogout('login'); 
    4142                                break; 
    42                         case "admin_logout": 
     43                        case 'admin_logout': 
    4344                                $h->adminLoginLogout('logout'); 
    4445                                break; 
    45                         case "admin_account": 
     46                        case 'admin_account': 
    4647                                $h->vars['admin_account'] = $this->adminAccount($h); 
    4748                                break; 
    48                         case "settings": 
     49                        case 'settings': 
    4950                                $h->vars['admin_settings'] = $this->settings($h); 
    5051                                break; 
    51                         case "maintenance": 
     52                        case 'maintenance': 
    5253                                $this->maintenanceAction($h); 
    5354                                $h->vars['admin_plugin_settings'] = $this->listPluginSettings($h); 
    5455                                $h->vars['admin_plugin_tables'] = $this->listDbTables($h, true); 
    5556                                break; 
    56                         case "blocked": 
     57                        case 'blocked': 
    5758                                $h->vars['admin_blocked_list'] = $this->blocked($h); 
    5859                                break; 
    59                         case "plugin_management": 
     60                        case 'plugin_management': 
    6061                                $h->sidebars = false; 
    6162                                $h->vars['admin_sidebar_layout'] = 'horizontal'; 
    6263                                $this->adminPlugins($h); 
    6364                                break; 
    64                         case "plugin_search": 
     65                        case 'plugin_search': 
    6566                                $h->sidebars = false; 
    6667                                $h->vars['admin_sidebar_layout'] = 'horizontal'; 
    6768                                //$this->adminPluginSearch($h);                          
    6869                                break; 
    69                         case "plugin_settings": 
     70                        case 'plugin_settings': 
    7071                                $h->vars['settings_plugin'] = $h->cage->get->testAlnumLines('plugin'); // get plugin name from url 
    71                                 if (!$h->vars['settings_plugin']) {  
     72                                if (!$h->vars['settings_plugin']) { 
    7273                                        $h->vars['settings_plugin'] = $h->cage->post->testAlnumLines('plugin');  // get plugin name from form 
    7374                                } 
    7475                                $h->vars['plugin_settings_csrf_error'] = ''; 
    75                                 if ($h->cage->post->testAlpha('submitted') == 'true') {  
     76                                if ($h->cage->post->testAlpha('submitted') == 'true') { 
    7677                                        $h->vars['plugin_settings_csrf_error'] = (!$h->csrf()) ? true : false; 
    7778                                } 
    7879                                $alt_template = $h->cage->get->testPage('alt_template'); 
    79                                 if ($alt_template) { $h->displayTemplate($alt_template, $h->vars['settings_plugin']); exit; } 
    80                                 break; 
    81                         case "theme_settings": 
     80                                if ($alt_template) { 
     81                                        $h->displayTemplate($alt_template, $h->vars['settings_plugin']); 
     82                                        exit; 
     83                                } 
     84                                break; 
     85                        case 'theme_settings': 
    8286                                $h->vars['settings_theme'] = $h->cage->get->testAlnumLines('theme'); // get plugin name from url 
    83                                 if (!$h->vars['settings_theme']) {  
     87                                if (!$h->vars['settings_theme']) { 
    8488                                        $h->vars['settings_theme'] = $h->cage->post->testAlnumLines('theme');  // get plugin name from form 
    8589                                } 
    8690                                $h->vars['theme_settings_csrf_error'] = ''; 
    87                                 if ($h->cage->post->testAlpha('submitted') == 'true') {  
     91                                if ($h->cage->post->testAlpha('submitted') == 'true') { 
    8892                                        $h->vars['theme_settings_csrf_error'] = (!$h->csrf()) ? true : false; 
    8993                                } 
     
    9498                                break; 
    9599                } 
    96                  
     100 
    97101                // Display the main theme's index.php template 
    98102                $h->displayTemplate('admin_index'); 
    99103        } 
    100          
    101          
    102         /* ************************************************************* 
    103         * 
    104         *  ACCOUNT PAGE 
    105         * 
    106         * *********************************************************** */ 
    107          
    108          
     104 
     105        /*       * ************************************************************ 
     106         * 
     107         *  ACCOUNT PAGE 
     108         * 
     109         * *********************************************************** */ 
     110 
    109111        /** 
    110112         * Call the updateAccount method in UserAuth 
    111          */     
     113         */ 
    112114        public function adminAccount($h) 
    113115        { 
    114116                return $h->currentUser->updateAccount($h); 
    115117        } 
    116          
    117          
    118         /* ************************************************************* 
    119         * 
    120         *  SETTINGS PAGE 
    121         * 
    122         * *********************************************************** */ 
    123          
    124          
     118 
     119        /*       * ************************************************************ 
     120         * 
     121         *  SETTINGS PAGE 
     122         * 
     123         * *********************************************************** */ 
     124 
    125125        /** 
    126126         * Process the settings form 
    127          */     
     127         */ 
    128128        public function settings($h) 
    129129        { 
    130                 $loaded_settings = $this->getAllAdminSettings($h->db);    // get all admin settings from the database 
    131                  
     130                // get all admin settings from the database 
     131                $loaded_settings = $this->getAllAdminSettings($h->db); 
     132 
    132133                $error = 0; 
    133                  
    134                 if ($h->cage->post->noTags('settings_update')  == 'true') { 
    135                  
     134 
     135                if ($h->cage->post->noTags('settings_update') == 'true') { 
     136 
    136137                        // if either the login or forgot password form is submitted, check the CSRF key 
    137                         if (!$h->csrf()) { $error = 1; } 
    138                          
     138                        if (!$h->csrf()) { 
     139                                $error = 1; 
     140                        } 
     141 
    139142                        foreach ($loaded_settings as $setting_name) { 
    140143                                if ($h->cage->post->keyExists($setting_name->settings_name)) { 
     
    142145                                        if (!$error && $setting_value && $setting_value != $setting_name->settings_value) { 
    143146                                                $this->adminSettingUpdate($h, $setting_name->settings_name, $setting_value); 
    144                                          
    145147                                        } else { 
    146148                                                if (!$setting_value) { 
     
    152154                                        // values that are allowed to be empty: 
    153155                                        $exempt = array('SMTP_USERNAME', 'SMTP_PASSWORD'); 
    154                                         if ($setting_name->settings_show == 'N') { array_push($exempt, $setting_name->settings_name); } 
    155                                         if (!in_array($setting_name->settings_name, $exempt)) {  
     156                                        if ($setting_name->settings_show == 'N') { 
     157                                                array_push($exempt, $setting_name->settings_name); 
     158                                        } 
     159                                        if (!in_array($setting_name->settings_name, $exempt)) { 
    156160                                                // otherwise flag as an error: 
    157161                                                $error = 1; 
    158                                         }  
     162                                        } 
    159163                                } 
    160164                        } 
    161                  
     165 
    162166                        $hook = "SystemInfo:hotaru_feedback"; 
    163                         $cron_data = array('hook'=>$hook); 
     167                        $cron_data = array('hook' => $hook); 
    164168                        $h->pluginHook('cron_delete_job', 'cron', $cron_data); 
    165169 
    166170                        $hook = "SystemInfo:hotaru_version"; 
    167                         $cron_data = array('hook'=>$hook); 
     171                        $cron_data = array('hook' => $hook); 
    168172                        $h->pluginHook('cron_delete_job', 'cron', $cron_data); 
    169                  
     173 
    170174                        if ($error == 0) { 
    171175                                $h->message = $h->lang['admin_settings_update_success']; 
     
    176180                        } 
    177181                } 
    178                  
     182 
    179183                // Activate themes from theme settings pages - called via JavaScript 
    180                 if ($h->cage->post->testAlnumLines('admin') == 'theme_settings' ) 
    181                 { 
    182                         $theme = strtolower($h->cage->post->testAlnumLines('theme') . "/" ); 
     184                if ($h->cage->post->testAlnumLines('admin') == 'theme_settings') { 
     185                        $theme = strtolower($h->cage->post->testAlnumLines('theme')."/"); 
    183186                        $this->adminSettingUpdate($h, 'THEME', $theme); 
    184                         $h->deleteFiles(CACHE . 'css_js_cache'); // clear the CSS/JS cache 
    185                         $json_array = array('activate'=>'true', 'message'=>$h->lang["admin_settings_theme_activate_success"], 'color'=>'green'); 
    186                          
     187                        $h->deleteFiles(CACHE.'css_js_cache'); // clear the CSS/JS cache 
     188                        $json_array = array('activate' => 'true', 'message' => $h->lang["admin_settings_theme_activate_success"], 'color' => 'green'); 
     189 
    187190                        // Send back result data 
    188191                        echo json_encode($json_array); 
    189192                        exit; 
    190193                } 
    191                  
    192                 $loaded_settings = $this->getAllAdminSettings($h->db); 
    193                  
    194                 return $loaded_settings; 
    195         } 
    196          
    197          
     194 
     195                return $this->getAllAdminSettings($h->db); 
     196        } 
     197 
    198198        /** 
    199199         * Returns all setting-value pairs 
     
    203203        public function getAllAdminSettings($db) 
    204204        { 
    205                 $sql = "SELECT settings_name, settings_value, settings_default, settings_note, settings_show FROM " . TABLE_SETTINGS; 
     205                $sql = "SELECT settings_name, settings_value, settings_default, settings_note, settings_show FROM ".TABLE_SETTINGS; 
    206206                $results = $db->get_results($db->prepare($sql)); 
    207                 if ($results) { return $results; } else { return false; } 
    208         } 
    209          
    210          
     207                if ($results) { 
     208                        return $results; 
     209                } 
     210                return FALSE; 
     211        } 
     212 
    211213        /** 
    212214         * Update an admin setting 
     
    218220        { 
    219221                $exists = $this->adminSettingExists($h->db, $setting); 
    220                  
     222 
    221223                if (!$exists) { 
    222                         $sql = "INSERT INTO " . TABLE_SETTINGS . " (settings_name, settings_value, settings_updateby) VALUES (%s, %s, %d)"; 
     224                        $sql = "INSERT INTO ".TABLE_SETTINGS." (settings_name, settings_value, settings_updateby) VALUES (%s, %s, %d)"; 
    223225                        $h->db->query($h->db->prepare($sql, $setting, $value, $h->currentUser->id)); 
    224226                } else { 
    225                         $sql = "UPDATE " . TABLE_SETTINGS . " SET settings_name = %s, settings_value = %s, settings_updateby = %d WHERE (settings_name = %s)"; 
     227                        $sql = "UPDATE ".TABLE_SETTINGS." SET settings_name = %s, settings_value = %s, settings_updateby = %d WHERE (settings_name = %s)"; 
    226228                        $h->db->query($h->db->prepare($sql, $setting, $value, $h->currentUser->id, $setting)); 
    227229                } 
    228230        } 
    229          
    230          
     231 
    231232        /** 
    232233         * Determine if a setting already exists 
     
    239240        public function adminSettingExists($db, $setting = '') 
    240241        { 
    241                 $sql = "SELECT settings_name FROM " . TABLE_SETTINGS . " WHERE (settings_name = %s)"; 
     242                $sql = "SELECT settings_name FROM ".TABLE_SETTINGS." WHERE (settings_name = %s)"; 
    242243                $returned_setting = $db->get_var($db->prepare($sql, $setting)); 
    243                 if ($returned_setting) { return $returned_setting; } else { return false; } 
    244         } 
    245          
    246          
    247         /* ************************************************************* 
    248         * 
    249         *  MAINTENANCE PAGE 
    250         * 
    251         * *********************************************************** */ 
    252          
    253          
     244                if ($returned_setting) { 
     245                        return $returned_setting; 
     246                } 
     247                return false; 
     248        } 
     249 
     250        /*       * ************************************************************ 
     251         * 
     252         *  MAINTENANCE PAGE 
     253         * 
     254         * *********************************************************** */ 
     255 
    254256        /** 
    255257         * Check action called in Maintenance template 
     
    257259        public function maintenanceAction($h) 
    258260        { 
    259                 require_once(LIBS . 'Maintenance.php'); 
    260261                $maintenance = new Maintenance(); 
    261262                $maintenance->getSiteAnnouncement($h); 
    262                  
     263 
    263264                // check if we're viewing a debug file 
    264265                $debug_file = $h->cage->get->noPath('debug'); 
     
    270271                        exit; 
    271272                } 
    272                  
     273 
    273274                // check if we're performing an action 
    274275                $action = $h->cage->get->testAlnumLines('action'); 
    275                  
    276                 if ($action == 'announcement') { $maintenance->addSiteAnnouncement($h); } 
    277                 if ($action == 'open') { $h->openCloseSite('open'); } 
    278                 if ($action == 'close') { $h->openCloseSite('close'); } 
    279                 if ($action == 'clear_all_cache') {  
    280                         $h->clearCache('db_cache', false); 
    281                         $h->clearCache('css_js_cache', false); 
    282                         $h->clearCache('rss_cache', false); 
    283                         $h->clearCache('html_cache', false); 
    284                         $h->clearCache('lang_cache', false); 
    285                         @unlink(BASE. 'cache/smartloader_cache.php'); 
    286                         $h->message = $h->lang['admin_maintenance_clear_all_cache_success']; 
    287                         $h->messageType = 'green'; 
    288                 } 
    289                 if ($action == 'clear_db_cache') { $h->clearCache('db_cache'); } 
    290                 if ($action == 'clear_css_js_cache') { $h->clearCache('css_js_cache'); } 
    291                 if ($action == 'clear_rss_cache') { $h->clearCache('rss_cache'); } 
    292                 if ($action == 'clear_html_cache') { $h->clearCache('html_cache'); } 
    293                 if ($action == 'clear_lang_cache') { $h->clearCache('lang_cache'); } 
    294                 if ($action == 'optimize') { $h->optimizeTables(); } 
    295                 if ($action == 'empty') { $h->emptyTable($h->cage->get->testAlnumLines('table')); } 
    296                 if ($action == 'drop') { $h->dropTable($h->cage->get->testAlnumLines('table')); } 
    297                 if ($action == 'remove_settings') { $h->removeSettings($h->cage->get->testAlnumLines('settings')); } 
    298                 if ($action == 'system_report') { $h->generateReport(); }  
    299                 if ($action == 'email_report') { $h->generateReport('email'); }  
    300                 if ($action == 'delete_debugs') {  
    301                         $h->clearCache('debug_logs'); 
    302                         $h->vars['debug_files'] = $h->getFiles(CACHE . 'debug_logs'); 
    303                 } 
    304                  
     276 
     277                switch ($h->cage->get->testAlnumLines('action')) { 
     278                        case 'announcement': 
     279                                $maintenance->addSiteAnnouncement($h); 
     280                                break; 
     281                        case 'open': 
     282                                $h->openCloseSite('open'); 
     283                                break; 
     284                        case 'close': 
     285                                $h->openCloseSite('close'); 
     286                                break; 
     287                        case 'clear_all_cache': 
     288                                $h->clearCache('db_cache', false); 
     289                                $h->clearCache('css_js_cache', false); 
     290                                $h->clearCache('rss_cache', false); 
     291                                $h->clearCache('html_cache', false); 
     292                                $h->clearCache('lang_cache', false); 
     293                                @unlink(BASE.'cache/smartloader_cache.php'); 
     294                                $h->message = $h->lang['admin_maintenance_clear_all_cache_success']; 
     295                                $h->messageType = 'green'; 
     296                                break; 
     297                                $h->openCloseSite('close'); 
     298                                break; 
     299                        case 'clear_db_cache': 
     300                                $h->clearCache('db_cache'); 
     301                                break; 
     302                        case 'clear_css_js_cache': 
     303                                $h->clearCache('css_js_cache'); 
     304                                break; 
     305                        case 'clear_rss_cache': 
     306                                $h->clearCache('rss_cache'); 
     307                                break; 
     308                        case 'clear_html_cache': 
     309                                $h->clearCache('html_cache'); 
     310                                break; 
     311                        case 'clear_lang_cache': 
     312                                $h->clearCache('lang_cache'); 
     313                                break; 
     314                        case 'optimize': 
     315                                $h->optimizeTables(); 
     316                                break; 
     317                        case 'empty': 
     318                                $h->emptyTable($h->cage->get->testAlnumLines('table')); 
     319                                break; 
     320                        case 'drop': 
     321                                $h->dropTable($h->cage->get->testAlnumLines('table')); 
     322                                break; 
     323                        case 'remove_settings': 
     324                                $h->removeSettings($h->cage->get->testAlnumLines('settings')); 
     325                                break; 
     326                        case 'system_report': 
     327                                $h->generateReport(); 
     328                                break; 
     329                        case 'email_report': 
     330                                $h->generateReport('email'); 
     331                                break; 
     332                        case 'delete_debugs': 
     333                                $h->clearCache('debug_logs'); 
     334                                $h->vars['debug_files'] = $h->getFiles(CACHE.'debug_logs'); 
     335                                break; 
     336                } 
     337 
    305338                // get list of debug logs 
    306                 $h->vars['debug_files'] = $h->getFiles(CACHE . 'debug_logs'); 
    307         } 
    308          
    309          
     339                $h->vars['debug_files'] = $h->getFiles(CACHE.'debug_logs'); 
     340        } 
     341 
    310342        /** 
    311343         * List all plugins with settings 
     
    315347        public function listPluginSettings($h) 
    316348        { 
     349                $sql = "SELECT DISTINCT plugin_folder FROM ".TABLE_PLUGINSETTINGS; 
     350                $results = $h->db->get_results($h->db->prepare($sql)); 
     351 
     352                if (!$results) { 
     353                        return false; 
     354                } 
     355 
    317356                $plugin_settings = array(); 
    318                 $sql = "SELECT DISTINCT plugin_folder FROM " . DB_PREFIX . "pluginsettings"; 
    319                 $results = $h->db->get_results($h->db->prepare($sql)); 
    320                  
    321                 if (!$results) { return false; }  
    322                  
     357 
    323358                foreach ($results as $item) { 
    324359                        array_push($plugin_settings, $item->plugin_folder); 
    325360                } 
    326                  
     361 
    327362                return $plugin_settings; 
    328363        } 
    329          
    330          
     364 
    331365        /** 
    332366         * List all created tables - used for emtying tables in Maintenance 
     
    337371        { 
    338372                $db_tables = array(); 
    339                  
     373 
    340374                if ($exclude_tables) { 
    341375                        $exclude = array( 
     
    356390 
    357391                $h->db->selectDB(DB_NAME); 
    358                  
    359                 if (!$h->db->get_col("SHOW TABLES",0)) { return $db_tables; } 
    360                  
    361                 foreach ( $h->db->get_col("SHOW TABLES",0) as $table_name ) 
    362                 { 
     392 
     393                if (!$h->db->get_col("SHOW TABLES", 0)) { 
     394                        return $db_tables; 
     395                } 
     396 
     397                foreach ($h->db->get_col("SHOW TABLES", 0) as $table_name) { 
    363398                        if ($exclude_tables) { 
    364399                                if (!in_array($table_name, $exclude)) { 
     
    369404                        } 
    370405                } 
    371                  
     406 
    372407                return $db_tables; 
    373408        } 
    374          
    375          
    376         /* ************************************************************* 
    377         * 
    378         *  BLOCKED PAGE 
    379         * 
    380         * *********************************************************** */ 
    381          
    382          
     409 
     410        /************************************************************** 
     411         * 
     412         *  BLOCKED PAGE 
     413         * 
     414         *************************************************************/ 
     415 
    383416        /** 
    384417         * Determine and respond to actions from the Blocked list 
     
    386419        public function blocked($h) 
    387420        { 
    388                 require_once(LIBS . 'Blocked.php'); 
    389421                $blocked = new Blocked(); 
    390422                $blocked_items = $blocked->buildBlockedList($h); 
    391                  
     423 
    392424                return $blocked_items; 
    393425        } 
    394          
    395          
    396         /* ************************************************************* 
    397         * 
    398         *  PLUGIN MANAGEMENT PAGE 
    399         * 
    400         * *********************************************************** */ 
    401  
    402  
    403          /** 
     426 
     427        /*       * ************************************************************ 
     428         * 
     429         *  PLUGIN MANAGEMENT PAGE 
     430         * 
     431         * *********************************************************** */ 
     432 
     433        /** 
    404434         * Call functions based on user actions in Plugin Management 
    405435         */ 
     
    408438                $pfolder = $h->cage->get->testAlnumLines('plugin'); 
    409439                $h->plugin->folder = $pfolder;   // assign this plugin to Hotaru 
    410                  
     440 
    411441                $action = $h->cage->get->testAlnumLines('action'); 
    412442                $order = $h->cage->get->testAlnumLines('order'); 
    413                                  
     443 
    414444                $plugman = new PluginManagement(); 
    415                  
     445 
    416446                switch ($action) { 
    417                         case "activate": 
     447                        case 'activate': 
    418448                                $plugman->activateDeactivate($h, 1); 
    419449                                break; 
    420                         case "deactivate": 
     450                        case 'deactivate': 
    421451                                $plugman->activateDeactivate($h, 0); 
    422                                 break;     
    423                         case "activate_all": 
     452                                break; 
     453                        case 'activate_all': 
    424454                                $plugman->activateDeactivateAll($h, 1); 
    425455                                break; 
    426                         case "deactivate_all": 
     456                        case 'deactivate_all': 
    427457                                $plugman->activateDeactivateAll($h, 0); 
    428                                 break;     
    429                         case "uninstall_all": 
     458                                break; 
     459                        case 'uninstall_all': 
    430460                                $plugman->uninstallAll($h); 
    431                                 break;     
    432                         case "install": 
     461                                break; 
     462                        case 'install': 
    433463                                $plugman->install($h); 
    434464                                break; 
    435                         case "uninstall": 
     465                        case 'uninstall': 
    436466                                $plugman->uninstall($h); 
    437                                 break;     
    438                         case "orderup": 
    439                                 $plugman->pluginOrder($h, $order, "up"); 
    440                                 break;     
    441                         case "orderdown": 
    442                                 $plugman->pluginOrder($h, $order, "down"); 
    443                                 break; 
    444                         case "update": 
     467                                break; 
     468                        case 'orderup': 
     469                                $plugman->pluginOrder($h, $order, 'up'); 
     470                                break; 
     471                        case 'orderdown': 
     472                                $plugman->pluginOrder($h, $order, 'down'); 
     473                                break; 
     474                        case 'update': 
    445475                                $plugman->activateDeactivate($h, 0); 
    446476                                $plugman->update($h); 
    447477                                $plugman->activateDeactivate($h, 1); 
    448478                                break; 
    449                         case "version_check": 
     479                        case 'version_check': 
    450480                                $plugman->versionCheck($h); 
    451481                                break; 
    452                         default: 
    453                                 // nothing to do here... 
    454                                 break; 
    455                 } 
    456                  
     482                } 
     483 
    457484                $plugman->refreshPluginDetails($h); 
    458                  
     485 
    459486                // get and sort all the plugins ready for display: 
    460487                $allplugins = $plugman->getPlugins($h);  // get plugins 
    461                  
     488 
    462489                $installed_plugins = array_filter($allplugins, array($plugman, 'getInstalledPlugins')); 
    463490                $h->vars['installed_plugins'] = sksort($installed_plugins, "order", "int", true); 
    464                  
     491 
    465492                $uninstalled_plugins = array_filter($allplugins, array($plugman, 'getUninstalledPlugins')); 
    466493                $h->vars['uninstalled_plugins'] = sksort($uninstalled_plugins, 'name', 'char', true); 
    467                  
     494 
    468495                return true; 
    469496        } 
     497 
    470498} 
    471 ?> 
  • branches/1.5/libs/Avatar.php

    r2035 r2292  
    11<?php 
     2 
    23/** 
    34 * Avatar class. Plugins that provide avatars should hook into this. 
     
    3738class Avatar 
    3839{ 
    39         public $user_id     = 0; 
    40         public $user_name   = ''; 
    41         public $user_email = ''; 
    42         public $size        = 32; 
    43         public $rating      = 'g';  // "global" used by Gravatar 
    44         public $valid       = true; 
    45          
    46          
     40 
     41        public $user_id = 0; 
     42        public $user_name = ''; 
     43        public $user_email = ''; 
     44        public $size = 32; 
     45        public $rating = 'g';  // "global" used by Gravatar 
     46        public $valid = true; 
     47 
    4748        /** 
    4849         * constructor 
     
    5354         * @param $rating avatar rating (g, pg, r or x in Gravatar) 
    5455         */ 
    55         public function  __construct($h, $user_id = 0, $size = 32, $rating = 'g') 
    56         { 
    57                 if (!$user_id) { return false; } 
    58                  
     56        public function __construct($h, $user_id = 0, $size = 32, $rating = 'g') 
     57        { 
     58                if (!$user_id) { 
     59                        return false; 
     60                } 
     61 
    5962                $this->user_id = $user_id; 
    60                  
     63 
    6164                $user = new UserBase(); 
    6265                $user->getUserBasic($h, $this->user_id); 
    6366                $this->user_email = $user->email; 
    6467                $this->user_name = $user->name; 
    65                  
     68 
    6669                $this->size = $size; 
    6770                $this->rating = $rating; 
    68                  
     71 
    6972                $this->setVars($h); 
    7073        } 
    71          
    72          
     74 
    7375        /** 
    7476         * Add Avatar properties to a vars array for plugins to use 
     
    7779        { 
    7880                $vars = array( 
    79                         'user_id'=>$this->user_id, 
    80                         'user_name'=>$this->user_name, 
    81                         'user_email'=>$this->user_email, 
    82                         'size'=>$this->size, 
    83                         'rating'=>$this->rating 
    84                         ); 
    85                  
     81                        'user_id' => $this->user_id, 
     82                        'user_name' => $this->user_name, 
     83                        'user_email' => $this->user_email, 
     84                        'size' => $this->size, 
     85                        'rating' => $this->rating 
     86                ); 
     87 
    8688                $h->pluginHook('avatar_set_avatar', '', $vars); 
    8789        } 
    88          
    89          
     90 
    9091        /** 
    9192         * test the avatar to see if it's valid 
     
    9596        public function testAvatar($h) 
    9697        { 
    97                 if (!$this->user_id) { return false; } 
    98                  
     98                if (!$this->user_id) { 
     99                        return false; 
     100                } 
     101 
    99102                $result = $h->pluginHook('avatar_test_avatar'); 
    100                  
     103 
    101104                if (!$result) { 
    102105                        $this->valid = false; 
    103106                        return false; 
    104                 }  
    105                  
     107                } 
     108 
    106109                $this->valid = true; 
    107110                return $result[key($result)];   // returns the result (i.e. Gravatar url in the case of Gravatar) 
    108          
    109         } 
    110          
    111          
     111        } 
     112 
    112113        /** 
    113114         * get the plain avatar with no surrounding HTML div 
     
    117118        public function getAvatar($h) 
    118119        { 
    119                 if (!$this->user_id) { return false; } 
    120                  
     120                if (!$this->user_id) { 
     121                        return false; 
     122                } 
     123 
    121124                $result = $h->pluginHook('avatar_get_avatar'); 
    122125                if ($result) { 
     
    126129                        return $avatar; // returns the last avatar sent to this hook 
    127130                } 
    128                  
     131 
    129132                return false; 
    130133        } 
    131          
    132          
     134 
    133135        /** 
    134136         * option to display the avatar linked to ther user's profile (image obtained from plugin) 
     
    136138        public function linkAvatar($h) 
    137139        { 
    138                 if (!$this->user_id) { return false; } 
    139                  
    140                 $output = "<a href='" . $h->url(array('user' => $this->user_name)) . "' title='" . $this->user_name . "'>"; 
     140                if (!$this->user_id) { 
     141                        return false; 
     142                } 
     143 
     144                $output = '<a href="'.$h->url(array('user' => $this->user_name)).'" title="'.$this->user_name.'">'; 
    141145                $result = $h->pluginHook('avatar_get_avatar'); 
    142146                if ($result) { 
     
    149153                return $output; 
    150154        } 
    151          
    152          
     155 
    153156        /** 
    154157         * option to display the profile-linked avatar wrapped in a div (image obtained from plugin) 
     
    156159        public function wrapAvatar($h) 
    157160        { 
    158                 if (!$this->user_id) { return false; } 
    159                  
     161                if (!$this->user_id) { 
     162                        return false; 
     163                } 
     164 
    160165                $output = "<div class='avatar_wrapper'>"; 
    161                 $output .= "<a href='" . $h->url(array('user' => $this->user_name)) . "' title='" . $this->user_name . "'>"; 
     166                $output .= "<a href='".$h->url(array('user' => $this->user_name))."' title='".$this->user_name."'>"; 
    162167                $result = $h->pluginHook('avatar_get_avatar'); 
    163168                if ($result) { 
     
    171176                return $output; 
    172177        } 
    173          
    174          
     178 
    175179        /** 
    176180         * option to display the avatar linked to ther user's profile (image already set) 
     
    178182        public function linkAvatarImage($h, $avatar_image = '') 
    179183        { 
    180                 if (!$this->user_id) { return false; } 
    181                  
    182                 $output = "<a href='" . $h->url(array('user' => $this->user_name)) . "' title='" . $this->user_name . "'>"; 
     184                if (!$this->user_id) { 
     185                        return false; 
     186                } 
     187 
     188                $output = "<a href='".$h->url(array('user' => $this->user_name))."' title='".$this->user_name."'>"; 
    183189                $output .= $avatar_image; // avatar in img tags 
    184190                $output .= "</a>"; 
    185191                return $output; 
    186192        } 
    187          
    188          
     193 
    189194        /** 
    190195         * option to display the profile-linked avatar wrapped in a div (image already set) 
     
    192197        public function wrapAvatarImage($h, $avatar_image = '') 
    193198        { 
    194                 if (!$this->user_id) { return false; } 
    195                  
     199                if (!$this->user_id) { 
     200                        return false; 
     201                } 
     202 
    196203                $output = "<div class='avatar_wrapper'>"; 
    197                 $output .= "<a href='" . $h->url(array('user' => $this->user_name)) . "' title='" . $this->user_name . "'>"; 
     204                $output .= "<a href='".$h->url(array('user' => $this->user_name))."' title='".$this->user_name."'>"; 
    198205                $output .= $avatar_image; // avatar in img tags 
    199206                $output .= "</a>"; 
     
    201208                return $output; 
    202209        } 
     210 
    203211} 
    204 ?> 
  • branches/1.5/libs/Comment.php

    r2168 r2292  
    2424 * @link      http://www.hotarucms.org/ 
    2525 */ 
    26      
    2726class Comment 
    2827{ 
    29         protected $id           = 0; 
    30         protected $parent       = 0; 
    31         protected $postId       = 0; 
    32         protected $author       = 0; 
    33         protected $date         = ''; 
    34         protected $status       = 'approved'; 
    35         protected $votes_up     = 0; 
    36         protected $votes_down   = 0; 
    37         protected $content      = ''; 
    38         protected $type         = 'newcomment';   // or "editcomment" 
    39         protected $subscribe    = 0; 
    40         protected $levels       = 0;         // max nesting levels 
    41         protected $depth        = 0;         // this nesting level 
    42         protected $email        = ''; 
     28 
     29        protected $id = 0; 
     30        protected $parent = 0; 
     31        protected $postId = 0; 
     32        protected $author = 0; 
     33        protected $date = ''; 
     34        protected $status = 'approved'; 
     35        protected $votes_up = 0; 
     36        protected $votes_down = 0; 
     37        protected $content = ''; 
     38        protected $type = 'newcomment';   // or "editcomment" 
     39        protected $subscribe = 0; 
     40        protected $levels = 0;   // max nesting levels 
     41        protected $depth = 0;   // this nesting level 
     42        protected $email = ''; 
    4343        protected $allowableTags = ''; 
    4444        protected $itemsPerPage = 20; 
    45         protected $pagination   = ''; 
    46         protected $thisForm     = ''; 
    47         protected $allForms     = 'checked'; 
    48         protected $avatars      = ''; 
    49         protected $avatarSize   = 16; 
    50         protected $voting       = ''; 
    51         protected $order        = 'asc';   // oldest comments first 
    52          
    53          
     45        protected $pagination = ''; 
     46        protected $thisForm = ''; 
     47        protected $allForms = 'checked'; 
     48        protected $avatars = ''; 
     49        protected $avatarSize = 16; 
     50        protected $voting = ''; 
     51        protected $order = 'asc';   // oldest comments first 
     52 
    5453        /** 
    5554         * Access modifier to set protected properties 
     
    5756        public function __set($var, $val) 
    5857        { 
    59                 $this->$var = $val;   
    60         } 
    61          
    62          
     58                $this->$var = $val; 
     59        } 
     60 
    6361        /** 
    6462         * Access modifier to get protected properties 
     
    6866                return $this->$var; 
    6967        } 
    70          
    71          
     68 
    7269        /** 
    7370         * Count comments 
     
    7976        function countComments($h, $digits_only = true, $no_comments_text = '') 
    8077        { 
    81                 $sql = "SELECT COUNT(comment_id) FROM " . TABLE_COMMENTS . " WHERE comment_post_id = %d AND comment_status = %s"; 
     78                $sql = "SELECT COUNT(comment_id) FROM ".TABLE_COMMENTS." WHERE comment_post_id = %d AND comment_status = %s"; 
    8279                $query = $h->db->prepare($sql, $h->post->id, 'approved'); 
    83                  
     80 
    8481                $h->smartCache('on', 'comments', 60, $query); // start using cache 
    8582                $num_comments = $h->db->get_var($query); 
    8683                $h->smartCache('off'); // stop using cache 
    87                  
    88                 if ($digits_only) { return $num_comments; } // just return the number 
    89                  
     84 
     85                if ($digits_only) { 
     86                        return $num_comments; 
     87                } // just return the number 
     88 
    9089                if ($num_comments == 1) { 
    91                         return "1 " . $h->lang['comments_singular_link']; 
     90                        return "1 ".$h->lang['comments_singular_link']; 
    9291                } elseif ($num_comments > 1) { 
    93                         return $num_comments . " " . $h->lang['comments_plural_link']; 
    94                 }  
    95                  
     92                        return $num_comments." ".$h->lang['comments_plural_link']; 
     93                } 
     94 
    9695                return $no_comments_text;  // shows "Leave a comment" above comment form when no comments 
    9796        } 
    98          
    99          
     97 
    10098        /** 
    10199         * Count all user comments 
     
    106104        function countUserComments($h, $user_id = 0) 
    107105        { 
    108                 if (!$user_id) { $user_id = $h->currentUser->id; } 
    109                  
    110                 $sql = "SELECT COUNT(comment_id) FROM " . TABLE_COMMENTS . " WHERE comment_user_id = %d AND comment_status = %s"; 
    111                 $query = $h->db->prepare($sql, $user_id , 'approved'); 
    112                  
     106                if (!$user_id) { 
     107                        $user_id = $h->currentUser->id; 
     108                } 
     109 
     110                $sql = "SELECT COUNT(comment_id) FROM ".TABLE_COMMENTS." WHERE comment_user_id = %d AND comment_status = %s"; 
     111                $query = $h->db->prepare($sql, $user_id, 'approved'); 
     112 
    113113                $h->smartCache('on', 'comments', 60, $query); // start using cache 
    114114                $num_comments = $h->db->get_var($query); 
    115115                $h->smartCache('off'); // stop using cache 
    116                  
    117                 return $num_comments;  
    118         } 
    119          
    120          
     116 
     117                return $num_comments; 
     118        } 
     119 
    121120        /** 
    122121         * Read all comment parents 
     
    127126        function readAllParents($h, $post_id, $order = "ASC") 
    128127        { 
    129                 $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_post_id = %d AND comment_parent = %d AND comment_status = %s ORDER BY comment_date " . $order; 
     128                $sql = "SELECT * FROM ".TABLE_COMMENTS." WHERE comment_post_id = %d AND comment_parent = %d AND comment_status = %s ORDER BY comment_date ".$order; 
    130129                $query = $h->db->prepare($sql, $post_id, 0, 'approved'); 
    131                  
     130 
    132131                $h->smartCache('on', 'comments', 60, $query); // start using cache 
    133132                $parents = $h->db->get_results($query); 
    134133                $h->smartCache('off'); // stop using cache 
    135                  
    136                 if($parents) { return $parents; } else { return false; } 
    137         } 
    138          
    139          
     134 
     135                if ($parents) { 
     136                        return $parents; 
     137                } 
     138                return false; 
     139        } 
     140 
    140141        /** 
    141142         * Read all comment children 
     
    146147        function readAllChildren($h, $parent) 
    147148        { 
     149                if(!$parent){ 
     150                        return FALSE; 
     151                } 
    148152                $fields = "comment_id, comment_post_id, comment_user_id, comment_parent, comment_date, comment_status, comment_content, comment_votes_up, comment_votes_down, comment_subscribe"; 
    149                  
    150                 $sql = "SELECT " . $fields . " FROM " . TABLE_COMMENTS . " WHERE comment_parent = %d AND comment_status = %s ORDER BY comment_date"; 
     153 
     154                $sql = "SELECT ".$fields." FROM ".TABLE_COMMENTS." WHERE comment_parent = %d AND comment_status = %s ORDER BY comment_date"; 
    151155                $query = $h->db->prepare($sql, $parent, 'approved'); 
    152                  
     156 
    153157                $h->smartCache('on', 'comments', 60, $query); // start using cache 
    154158                $children = $h->db->get_results($query); 
    155159                $h->smartCache('off'); // stop using cache 
    156                  
    157                 if($children) { return $children; } else { return false; } 
    158         } 
    159          
    160          
     160 
     161                if ($children) { 
     162                        return $children; 
     163                } 
     164                return false; 
     165        } 
     166 
    161167        /** 
    162168         * Get comment from database 
     
    167173        function getComment($h, $comment_id = 0) 
    168174        { 
    169                 $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_id = %d"; 
     175                $sql = "SELECT * FROM ".TABLE_COMMENTS." WHERE comment_id = %d"; 
    170176                $query = $h->db->prepare($sql, $comment_id); 
    171                  
     177 
    172178                $h->smartCache('on', 'comments', 60, $query); // start using cache 
    173179                $comment = $h->db->get_row($query); 
    174180                $h->smartCache('off'); // stop using cache 
    175                  
    176                 if($comment) { return $comment; } else { return false; } 
    177         } 
    178          
    179          
     181 
     182                if ($comment) { 
     183                        return $comment; 
     184                } 
     185                return false; 
     186        } 
     187 
    180188        /** 
    181189         * Get all comments from database 
     
    187195        { 
    188196                // limiting is used in the rssFeed function. Other than that, pagination does limiting for us. 
    189                 if(!$limit) { $limit = ''; } else { $limit = " LIMIT "  .$limit; } 
    190                  
     197                $limit = ($limit) ? " LIMIT ".$limit : ''; 
     198 
    191199                if ($post_id) { 
    192200                        // get all comments from specified post 
    193                         $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_post_id = %d AND comment_status = %s ORDER BY comment_date " . $order; 
     201                        $sql = "SELECT * FROM ".TABLE_COMMENTS." WHERE comment_post_id = %d AND comment_status = %s ORDER BY comment_date ".$order; 
    194202                        $query = $h->db->prepare($sql, $post_id, 'approved'); 
    195203                        $h->smartCache('on', 'comments', 60, $query); // start using cache 
     
    197205                } else { 
    198206                        // get all comments 
    199                         if ($userid) {  
    200                                 $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s AND comment_status = %s AND comment_user_id = %d ORDER BY comment_date " . $order . $limit; 
     207                        if ($userid) { 
     208                                $sql = "SELECT * FROM ".TABLE_COMMENTS." WHERE comment_archived = %s AND comment_status = %s AND comment_user_id = %d ORDER BY comment_date ".$order.$limit; 
    201209                                $query = $h->db->prepare($sql, 'N', 'approved', $userid); 
    202210                                $h->smartCache('on', 'comments', 60, $query); // start using cache 
    203211                                $comments = $h->db->get_results($query); 
    204212                        } else { 
    205                                 $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s AND comment_status = %s ORDER BY comment_date " . $order . $limit; 
     213                                $sql = "SELECT * FROM ".TABLE_COMMENTS." WHERE comment_archived = %s AND comment_status = %s ORDER BY comment_date ".$order.$limit; 
    206214                                $query = $h->db->prepare($sql, 'N', 'approved'); 
    207                                 $h->smartCache('on', 'comments', 60, $query ); // start using cache 
    208                                 $comments = $h->db->get_results($query ); 
     215                                $h->smartCache('on', 'comments', 60, $query); // start using cache 
     216                                $comments = $h->db->get_results($query); 
    209217                        } 
    210218                } 
    211219                $h->smartCache('off'); // stop using cache 
    212                  
    213                 if($comments) { return $comments; } else { return false; } 
    214         } 
    215          
    216          
     220 
     221                if ($comments) { 
     222                        return $comments; 
     223                } 
     224                return false; 
     225        } 
     226 
    217227        /** 
    218228         * Get all comments from database 
     
    224234        { 
    225235                // get all comments 
    226                 if ($userid) {  
    227                         $sql = "SELECT count(*) AS number FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s AND comment_status = %s AND comment_user_id = %d ORDER BY comment_date " . $order; 
     236                if ($userid) { 
     237                        $sql = "SELECT count(*) AS number FROM ".TABLE_COMMENTS." WHERE comment_archived = %s AND comment_status = %s AND comment_user_id = %d ORDER BY comment_date ".$order; 
    228238                        $query = $h->db->prepare($sql, 'N', 'approved', $userid); 
    229239                        $h->smartCache('on', 'comments', 60, $query); // start using cache 
    230240                        $comment_count = $h->db->get_var($query); 
    231241                } else { 
    232                         $sql = "SELECT count(*) AS number FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s AND comment_status = %s ORDER BY comment_date " . $order; 
     242                        $sql = "SELECT count(*) AS number FROM ".TABLE_COMMENTS." WHERE comment_archived = %s AND comment_status = %s ORDER BY comment_date ".$order; 
    233243                        $query = $h->db->prepare($sql, 'N', 'approved'); 
    234244                        $h->smartCache('on', 'comments', 60, $query); // start using cache 
     
    236246                } 
    237247                $h->smartCache('off'); // stop using cache 
    238                  
    239                 if($comment_count) { return $comment_count; } else { return false; } 
    240         } 
    241          
    242          
     248 
     249                if ($comment_count) { 
     250                        return $comment_count; 
     251                } 
     252                return false; 
     253        } 
     254 
    243255        /** 
    244256         * Get all comments from database 
     
    250262        { 
    251263                // get all comments 
    252                 if ($userid) {  
    253                         $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_status = %s AND comment_user_id = %d ORDER BY comment_date " . $order; 
     264                if ($userid) { 
     265                        $sql = "SELECT * FROM ".TABLE_COMMENTS." WHERE comment_status = %s AND comment_user_id = %d ORDER BY comment_date ".$order; 
    254266                        $query = $h->db->prepare($sql, 'approved', $userid); 
    255267                } else { 
    256                         $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_status = %s ORDER BY comment_date " . $order; 
     268                        $sql = "SELECT * FROM ".TABLE_COMMENTS." WHERE comment_status = %s ORDER BY comment_date ".$order; 
    257269                        $query = $h->db->prepare($sql, 'approved'); 
    258270                } 
    259                  
    260                 if($query) { return $query; } else { return false; } 
    261         } 
    262          
    263          
     271 
     272                if ($query) { 
     273                        return $query; 
     274                } 
     275                return false; 
     276        } 
     277 
    264278        /** 
    265279         * Read comment 
     
    269283        function readComment($h, $comment = array()) 
    270284        { 
     285 
    271286                $this->id = $comment->comment_id; 
    272287                $this->parent = $comment->comment_parent; 
     
    279294                $this->content = urldecode($comment->comment_content); 
    280295                $this->subscribe = $comment->comment_subscribe; 
    281                  
     296 
    282297                $h->pluginHook('comment_read_comment'); 
    283                  
     298 
    284299                return $this; 
    285300        } 
    286          
    287          
     301 
    288302        /** 
    289303         * Add comment 
     
    293307        function addComment($h) 
    294308        { 
    295                 $sql = "INSERT INTO " . TABLE_COMMENTS . " SET comment_post_id = %d, comment_user_id = %d, comment_parent = %d, comment_date = CURRENT_TIMESTAMP, comment_status = %s, comment_content = %s, comment_subscribe = %d, comment_updateby = %d"; 
    296                  
     309                $sql = "INSERT INTO ".TABLE_COMMENTS." SET comment_post_id = %d, comment_user_id = %d, comment_parent = %d, comment_date = CURRENT_TIMESTAMP, comment_status = %s, comment_content = %s, comment_subscribe = %d, comment_updateby = %d"; 
     310 
    297311                $h->db->query($h->db->prepare($sql, $this->postId, $this->author, $this->parent, $this->status, urlencode(trim(stripslashes($this->content))), $this->subscribe, $h->currentUser->id)); 
    298                  
     312 
    299313                $last_insert_id = $h->db->get_var($h->db->prepare("SELECT LAST_INSERT_ID()")); 
    300                  
     314 
    301315                $this->id = $last_insert_id; 
    302                 $h->vars['last_insert_id'] = $last_insert_id;    // make it available outside this class 
    303                  
     316                $h->vars['last_insert_id'] = $last_insert_id; // make it available outside this class 
     317 
    304318                $h->pluginHook('comment_post_add_comment'); 
    305319        } 
    306320 
    307                  
    308321        /** 
    309322         * Edit comment 
     
    313326        function editComment($h) 
    314327        { 
    315                 $sql = "UPDATE " . TABLE_COMMENTS . " SET comment_status = %s, comment_content = %s, comment_subscribe = %d, comment_updateby = %d WHERE comment_id = %d"; 
     328                $sql = "UPDATE ".TABLE_COMMENTS." SET comment_status = %s, comment_content = %s, comment_subscribe = %d, comment_updateby = %d WHERE comment_id = %d"; 
    316329                $h->db->query($h->db->prepare($sql, $this->status, urlencode(trim(stripslashes($this->content))), $this->subscribe, $h->currentUser->id, $this->id)); 
    317                  
     330 
    318331                $h->comment->id = $this->id; // a small hack to get the id for use in plugins. 
    319332                $h->pluginHook('comment_update_comment'); 
    320                  
     333 
    321334                return true; 
    322335        } 
    323          
    324          
     336 
    325337        /** 
    326338         * Physically delete a comment from the database  
    327339         * 
    328          */     
     340         */ 
    329341        public function deleteComment($h, $comment_id = 0) 
    330342        { 
    331                 if (!$comment_id) { $comment_id = $this->id; } 
    332                 if (!$comment_id) { return false; } 
    333                  
    334                 $sql = "DELETE FROM " . TABLE_COMMENTS . " WHERE comment_id = %d"; 
     343                if (!$comment_id) { 
     344                        $comment_id = $this->id; 
     345                } 
     346                if (!$comment_id) { 
     347                        return false; 
     348                } 
     349 
     350                $sql = "DELETE FROM ".TABLE_COMMENTS." WHERE comment_id = %d"; 
    335351                $h->db->query($h->db->prepare($sql, $comment_id)); 
    336                  
     352 
    337353                // delete any votes for this comment 
    338                 $sql = "DELETE FROM " . TABLE_COMMENTVOTES . " WHERE cvote_comment_id = %d"; 
     354                $sql = "DELETE FROM ".TABLE_COMMENTVOTES." WHERE cvote_comment_id = %d"; 
    339355                $h->db->query($h->db->prepare($sql, $this->id)); 
    340                  
     356 
    341357                $h->comment->id = $comment_id; // a small hack to get the id for use in plugins. 
    342358                $h->pluginHook('comment_delete_comment'); 
    343                  
     359 
    344360                // Need to clear both these caches to be sure related items are updated in widgets, etc.: 
    345                 $h->clearCache('html_cache', false);  
    346                 $h->clearCache('db_cache', false);  
    347         } 
    348          
    349          
     361                $h->clearCache('html_cache', false); 
     362                $h->clearCache('db_cache', false); 
     363        } 
     364 
    350365        /** 
    351366         * Physically delete all comments by a specified user (and responses) 
     
    354369         * @return bool 
    355370         */ 
    356         public function deleteComments($h, $user_id = 0)  
    357         { 
    358                 if (!$user_id) { return false; } 
    359                  
    360                 $sql = "SELECT comment_id FROM " . DB_PREFIX . "comments WHERE comment_user_id = %d"; 
     371        public function deleteComments($h, $user_id = 0) 
     372        { 
     373                if (!$user_id) { 
     374                        return false; 
     375                } 
     376 
     377                $sql = "SELECT comment_id FROM ".TABLE_COMMENTS." WHERE comment_user_id = %d"; 
    361378                $results = $h->db->get_results($h->db->prepare($sql, $user_id)); 
    362                  
     379 
    363380                if ($results) { 
    364381                        foreach ($results as $r) { 
    365382                                $h->comment->id = $r->comment_id;   // used by other plugins in "comment_delete_comment" function/hook 
    366                                 $this->deleteComment($h, $h->comment->id);    // delete parent comment 
     383                                $this->deleteComment($h, $h->comment->id); // delete parent comment 
    367384                                $this->deleteCommentTree($h, $h->comment->id);  // delete all children of that comment regardless of user 
    368385                        } 
    369386                } 
    370                  
     387 
    371388                return true; 
    372389        } 
    373          
    374          
     390 
    375391        /** 
    376392         * Recurse through comment tree, deleting all 
     
    389405                                } 
    390406                        } 
    391          
     407 
    392408                        return false; 
    393409                } 
    394410        } 
    395          
    396          
     411 
    397412        /** 
    398413         * Recurse through comment tree, setting all to 'pending' 
     
    412427                                } 
    413428                        } 
    414                          
     429 
    415430                        return false; 
    416431                } 
    417432        } 
    418          
    419          
     433 
    420434        /** 
    421435         * Determine if the comment form is open or closed 
     
    427441        { 
    428442                if ($type == 'select') { 
    429                         $sql = "SELECT post_comments FROM " . TABLE_POSTS . " WHERE post_id = %d"; 
     443                        $sql = "SELECT post_comments FROM ".TABLE_POSTS." WHERE post_id = %d"; 
    430444                        $form_status = $h->db->get_var($h->db->prepare($sql, $h->post->id)); 
    431                          
    432                         if ($form_status) { return $form_status; } else { return 'open'; } // default 'open' 
    433                 } 
    434                  
     445 
     446                        if ($form_status) { 
     447                                return $form_status; 
     448                        } else { 
     449                                return 'open'; 
     450                        } // default 'open' 
     451                } 
     452 
    435453                if ($type == 'open' || $type == 'closed') { 
    436454                        $h->comment->form = $type; 
    437                         $sql = "UPDATE " . TABLE_POSTS . " SET post_comments = %s WHERE post_id = %d"; 
     455                        $sql = "UPDATE ".TABLE_POSTS." SET post_comments = %s WHERE post_id = %d"; 
    438456                        $h->db->query($h->db->prepare($sql, $type, $h->post->id)); 
    439457                } 
    440458        } 
    441          
    442          
     459 
    443460        /** 
    444461         * Unsubscribe from a thread 
     
    450467        { 
    451468                $h->readPost($post_id); 
    452          
    453                 $sql = "UPDATE " . TABLE_COMMENTS . " SET comment_subscribe = %d WHERE comment_post_id = %d AND comment_user_id = %d"; 
     469 
     470                $sql = "UPDATE ".TABLE_COMMENTS." SET comment_subscribe = %d WHERE comment_post_id = %d AND comment_user_id = %d"; 
    454471                $h->db->query($h->db->prepare($sql, 0, $h->post->id, $h->currentUser->id)); 
    455472 
    456473                // Check if the currentUser is the post author 
    457474                if ($h->post->author == $h->currentUser->id) { 
    458                 // Check if the user subscribed to comments as a submitter 
    459                         if ($h->post->subscribe == 1) {  
    460                                 $sql = "UPDATE " . TABLE_POSTS . " SET post_subscribe = %d WHERE post_id = %d AND post_author = %d"; 
     475                        // Check if the user subscribed to comments as a submitter 
     476                        if ($h->post->subscribe == 1) { 
     477                                $sql = "UPDATE ".TABLE_POSTS." SET post_subscribe = %d WHERE post_id = %d AND post_author = %d"; 
    461478                                $h->db->query($h->db->prepare($sql, 0, $h->post->id, $h->currentUser->id)); 
    462                         }  
     479                        } 
    463480                } 
    464481                return true; 
    465482        } 
    466          
    467          
     483 
    468484        /** 
    469485         * Update thread subscription  
     
    474490        function updateSubscribe($h, $post_id) 
    475491        { 
    476                 if ($this->subscribe == 1) 
    477                 { 
    478                         $sql = "UPDATE " . TABLE_COMMENTS . " SET comment_subscribe = %d WHERE comment_post_id = %d AND comment_user_id = %d"; 
     492                if ($this->subscribe == 1) { 
     493                        $sql = "UPDATE ".TABLE_COMMENTS." SET comment_subscribe = %d WHERE comment_post_id = %d AND comment_user_id = %d"; 
    479494                        $h->db->query($h->db->prepare($sql, 1, $h->post->id, $h->currentUser->id)); 
    480                 }  
    481                 else  
    482                 { 
     495                } else { 
    483496                        $this->unsubscribe($h, $post_id); 
    484497                } 
    485498        } 
    486          
    487          
     499 
    488500        /** 
    489501         * Count how many approved comments a user has had 
     
    494506        public function commentsApproved($h, $userid) 
    495507        { 
    496                 $sql = "SELECT COUNT(*) FROM " . TABLE_COMMENTS . " WHERE comment_status = %s AND comment_user_id = %d"; 
     508                $sql = "SELECT COUNT(*) FROM ".TABLE_COMMENTS." WHERE comment_status = %s AND comment_user_id = %d"; 
    497509                $query = $h->db->prepare($sql, 'approved', $userid); 
    498                  
     510 
    499511                $h->smartCache('on', 'comments', 60, $query); // start using cache 
    500512                $count = $h->db->get_var($query); 
    501513                $h->smartCache('off'); // stop using cache 
    502                  
     514 
    503515                return $count; 
    504516        } 
    505          
    506          
     517 
    507518        /** 
    508519         * Count daily comments for this commenter 
     
    514525                $start = date('YmdHis', time_block()); 
    515526                $end = date('YmdHis', strtotime("-1 day")); 
    516                 $sql = "SELECT COUNT(comment_id) FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s AND comment_user_id = %d AND (comment_date >= %s AND comment_date <= %s)"; 
     527                $sql = "SELECT COUNT(comment_id) FROM ".TABLE_COMMENTS." WHERE comment_archived = %s AND comment_user_id = %d AND (comment_date >= %s AND comment_date <= %s)"; 
    517528                $query = $h->db->prepare($sql, 'N', $this->author, $end, $start); 
    518                  
     529 
    519530                $h->smartCache('on', 'comments', 60, $query); // start using cache 
    520531                $count = $h->db->get_var($query); 
    521532                $h->smartCache('off'); // stop using cache 
    522                  
     533 
    523534                return $count; 
    524535        } 
    525          
    526          
     536 
    527537        /** 
    528538         * Count urls in comment 
     
    534544        { 
    535545                $text = $this->content; 
    536                  
     546 
    537547                //$http = substr_count($text, "http"); 
    538548                $href = substr_count($text, "href"); 
    539549                $url = substr_count($text, "[url"); 
    540                  
     550 
    541551                return $href + $url; 
    542552        } 
    543          
    544          
     553 
    545554        /** 
    546555         * Stats for Admin homepage 
     
    550559         */ 
    551560        public function stats($h, $stat_type = '') 
    552         {                
     561        { 
    553562                switch ($stat_type) { 
    554                     default: 
    555                         $sql = "SELECT comment_status, count(comment_id) FROM " . TABLE_COMMENTS . " GROUP BY comment_status"; 
    556                         $query = $h->db->prepare($sql); 
    557                         $h->smartCache('on', 'comments', 60, $query); // start using cache 
    558                         $comments = $h->db->get_results($query, 'ARRAY_N'); 
    559                         break; 
    560                     case 'archived': 
    561                         $sql = "SELECT count(comment_id) FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s"; 
    562                         $query = $h->db->prepare($sql, 'Y'); 
    563                         $h->smartCache('on', 'comments', 60, $query); // start using cache 
    564                         $comments = $h->db->get_var($query); 
    565                         break; 
     563                        case 'archived': 
     564                                $sql = "SELECT count(comment_id) FROM ".TABLE_COMMENTS." WHERE comment_archived = %s"; 
     565                                $query = $h->db->prepare($sql, 'Y'); 
     566                                $h->smartCache('on', 'comments', 60, $query); // start using cache 
     567                                $comments = $h->db->get_var($query); 
     568                                break; 
     569                        default: 
     570                                $sql = "SELECT comment_status, count(comment_id) FROM ".TABLE_COMMENTS." GROUP BY comment_status"; 
     571                                $query = $h->db->prepare($sql); 
     572                                $h->smartCache('on', 'comments', 60, $query); // start using cache 
     573                                $comments = $h->db->get_results($query, 'ARRAY_N'); 
     574                                break; 
    566575                } 
    567576 
     
    569578 
    570579                return $comments; 
    571  
    572         } 
     580        } 
     581 
    573582} 
    574 ?> 
  • branches/1.5/libs/Database.php

    r2285 r2292  
    307307                // Extract var out of cached results based col,row vals 
    308308                if ($this->last_result[$row]) { 
     309                        unset($this->last_result['CLASSNAME']); 
    309310                        $values = array_values(get_object_vars($this->last_result[$row])); 
    310311                } 
  • branches/1.5/libs/Debug.php

    r2255 r2292  
    11<?php 
     2 
    23/** 
    34 * Debugging functions 
     
    2425 * @link      http://www.hotarucms.org/ 
    2526 */ 
    26 class Debug { 
     27class Debug 
     28{ 
    2729 
    2830        /** 
     
    7577                } 
    7678 
    77                 if(!file_exists($filename)) 
    78                 { 
     79                if (!file_exists($filename)) { 
    7980                        file_put_contents($filename, "<?php die();?>\n"); 
    8081                } 
  • branches/1.5/libs/EmailFunctions.php

    r2276 r2292  
    2525 * @link      http://www.hotarucms.org/ 
    2626 */ 
    27 class EmailFunctions { 
     27class EmailFunctions 
     28{ 
    2829 
    2930        /** 
     
    8889                switch ($type) { 
    8990                        case 'log': 
    90                                 require_once(LIBS.'Debug.php'); 
    91                                 $content = $headers."\n".$to."\n".$subject."\n".$body."\n\n"; 
    92                                 $content .= "**************************************************************\n\n"; 
    93                                 Debug::log('email_log', $content); 
     91                                Debug::log('email_log', $headers."\n".$to."\n".$subject."\n".$body."\n\n**************************************************************\n\n"); 
    9492                                break; 
    9593                        case 'screen': 
     
    112110                                break; 
    113111                        default: 
    114                                 if (SMTP == 'true') { 
    115                                         //  Only create a new smtp object if we don't already have one: 
    116                                         require_once "Mail.php"; 
    117                                         $smtp = Mail::factory('smtp', array( 
    118                                                                 'host' => SMTP_HOST, 
    119                                                                 'port' => SMTP_PORT, 
    120                                                                 'auth' => TRUE, 
    121                                                                 'username' => SMTP_USERNAME, 
    122                                                                 'password' => SMTP_PASSWORD 
    123                                                         )); 
     112                                if (SMTP != 'true') { 
     113                                        return mail($to, $subject, $body, $headers); 
     114                                } 
    124115 
    125                                         $mail = $smtp->send($to, $headers, $body); 
     116                                //  Only create a new smtp object if we don't already have one: 
     117                                require_once "Mail.php"; 
     118                                $smtp = Mail::factory('smtp', array( 
     119                                                        'host' => SMTP_HOST, 
     120                                                        'port' => SMTP_PORT, 
     121                                                        'auth' => TRUE, 
     122                                                        'username' => SMTP_USERNAME, 
     123                                                        'password' => SMTP_PASSWORD 
     124                                                )); 
    126125 
    127                                         if (PEAR::isError($mail)) { 
    128                                                 echo("<p>".$mail->getMessage()."</p>"); 
    129                                                 exit; 
    130                                         } 
    131                                 } else { 
    132                                         $sentmail = mail($to, $subject, $body, $headers); 
     126                                $mail = $smtp->send($to, $headers, $body); 
     127                                if (PEAR::isError($mail)) { 
     128                                        echo("<p>".$mail->getMessage()."</p>"); 
     129                                        exit; 
    133130                                } 
    134131                } 
     
    136133 
    137134} 
    138  
    139 ?> 
  • branches/1.5/libs/Initialize.php

    r2257 r2292  
    112112                // define database tables 
    113113                $tableConstants = array( 
    114                         "TABLE_BLOCKED" => "blocked", 
    115                         "TABLE_CATEGORIES" => "categories", 
    116                         "TABLE_COMMENTS" => "comments", 
    117                         "TABLE_COMMENTVOTES" => "commentvotes", 
    118                         "TABLE_FRIENDS" => "friends", 
    119                         "TABLE_MESSAGING" => "messaging", 
    120                         "TABLE_MISCDATA" => "miscdata", 
    121                         "TABLE_PLUGINS" => "plugins", 
    122                         "TABLE_PLUGINHOOKS" => "pluginhooks", 
    123                         "TABLE_PLUGINSETTINGS" => "pluginsettings", 
    124                         "TABLE_POSTS" => "posts", 
    125                         "TABLE_POSTMETA" => "postmeta", 
    126                         "TABLE_POSTVOTES" => "postvotes", 
    127                         "TABLE_SETTINGS" => "settings", 
    128                         "TABLE_TAGS" => "tags", 
    129                         "TABLE_TEMPDATA" => "tempdata", 
    130                         "TABLE_USERS" => "users", 
    131                         "TABLE_USERMETA" => "usermeta", 
    132                         "TABLE_USERACTIVITY" => "useractivity", 
    133                         "TABLE_WIDGETS" => "widgets" 
     114                        'TABLE_BLOCKED' => 'blocked', 
     115                        'TABLE_CATEGORIES' => 'categories', 
     116                        'TABLE_COMMENTS' => 'comments', 
     117                        'TABLE_FRIENDS' => 'friends', 
     118                        'TABLE_MESSAGING' => 'messaging', 
     119                        'TABLE_MISCDATA' => 'miscdata', 
     120                        'TABLE_PLUGINS' => 'plugins', 
     121                        'TABLE_PLUGINHOOKS' => 'pluginhooks', 
     122                        'TABLE_PLUGINSETTINGS' => 'pluginsettings', 
     123                        'TABLE_POSTS' => 'posts', 
     124                        'TABLE_POSTMETA' => 'postmeta', 
     125                        'TABLE_POSTVOTES' => 'postvotes', 
     126                        'TABLE_SETTINGS' => 'settings', 
     127                        'TABLE_TAGS' => 'tags', 
     128                        'TABLE_TEMPDATA' => 'tempdata', 
     129                        'TABLE_USERS' => 'users', 
     130                        'TABLE_USERMETA' => 'usermeta', 
     131                        'TABLE_USERACTIVITY' => 'useractivity', 
     132                        'TABLE_WIDGETS' => 'widgets', 
     133                        'TABLE_TOKENS' => 'tokens' 
    134134                ); 
    135  
    136135                foreach ($tableConstants as $key => $value) { 
    137136                        if (!defined($key)) { 
  • branches/1.5/libs/InspektExtras.php

    r2191 r2292  
    2424 * @link      http://www.hotarucms.org/ 
    2525 */ 
    26   
    27 require_once(EXTENSIONS . 'Inspekt/Inspekt/AccessorAbstract.php'); 
    28   
    29 class testAlnumLines extends AccessorAbstract  
     26require_once(EXTENSIONS.'Inspekt/Inspekt/AccessorAbstract.php'); 
     27 
     28class testAlnumLines extends AccessorAbstract 
    3029{ 
     30 
    3131        /** 
    32         * a function to test for chars, digits, underscores and dashes. 
    33         * 
    34         * @return bool 
    35         */ 
     32         * a function to test for chars, digits, underscores and dashes. 
     33         * 
     34         * @return bool 
     35         */ 
    3636        protected function inspekt($val) 
    3737        { 
     
    4242                } 
    4343        } 
     44 
    4445} 
    45  
    4646 
    4747class testPage extends AccessorAbstract 
    4848{ 
     49 
    4950        /** 
    50         * a function to test for a valid pagename 
    51         * 
    52         * @return bool 
    53         */ 
     51         * a function to test for a valid pagename 
     52         * 
     53         * @return bool 
     54         */ 
    5455        protected function inspekt($val) 
    5556        { 
     
    6061                } 
    6162        } 
     63 
    6264} 
    63  
    6465 
    6566class testUsername extends AccessorAbstract 
    6667{ 
     68 
    6769        /** 
    68         * a function to test for a valid username 
    69         * 
    70         * @return bool 
    71         */ 
     70         * a function to test for a valid username 
     71         * 
     72         * @return bool 
     73         */ 
    7274        protected function inspekt($val) 
    7375        { 
     
    7880                } 
    7981        } 
     82 
    8083} 
    81  
    8284 
    8385class testPassword extends AccessorAbstract 
    8486{ 
     87 
    8588        /** 
    86         * a function to test for a valid password 
    87         * 
    88         * @return bool 
    89         */ 
     89         * a function to test for a valid password 
     90         * 
     91         * @return bool 
     92         */ 
    9093        protected function inspekt($val) 
    9194        { 
    9295                if (preg_match('/^([a-z0-9!@*#_-]{8,60})+$/i', $val)) { 
    9396                        return $val; 
    94                 } else { 
    95                         return false; 
    9697                } 
     98                return false; 
    9799        } 
     100 
    98101} 
    99  
    100102 
    101103class getFriendlyUrl extends AccessorAbstract 
    102104{ 
     105 
    103106        /** 
    104         * a function to makea url friendly 
    105         * 
    106         * @return string 
    107         */ 
     107         * a function to makea url friendly 
     108         * 
     109         * @return string 
     110         */ 
    108111        protected function inspekt($val) 
    109112        { 
    110113                return make_url_friendly($val); 
    111114        } 
     115 
    112116} 
    113  
    114117 
    115118class sanitizeAll extends AccessorAbstract 
    116119{ 
     120 
    117121        /** 
    118         * a function to sanitize a string with htmlentities and strip_tags 
    119         * 
    120         * @return string 
    121         */ 
     122         * a function to sanitize a string with htmlentities and strip_tags 
     123         * 
     124         * @return string 
     125         */ 
    122126        protected function inspekt($val) 
    123127        { 
    124128                return sanitize($val, 'all'); 
    125129        } 
     130 
    126131} 
    127  
    128132 
    129133class sanitizeTags extends AccessorAbstract 
    130134{ 
     135 
    131136        /** 
    132         * a function to sanitize a string with strip_tags 
    133         * 
    134         * @return string 
    135         */ 
     137         * a function to sanitize a string with strip_tags 
     138         * 
     139         * @return string 
     140         */ 
    136141        protected function inspekt($val) 
    137142        { 
    138143                return sanitize($val, 'tags'); 
    139144        } 
     145 
    140146} 
    141147 
    142148class sanitizeEnts extends AccessorAbstract 
    143149{ 
     150 
    144151        /** 
    145         * a function to sanitize with htmlentities 
    146         * 
    147         * @return string 
    148         */ 
     152         * a function to sanitize with htmlentities 
     153         * 
     154         * @return string 
     155         */ 
    149156        protected function inspekt($val) 
    150157        { 
    151158                return sanitize($val, 'ents'); 
    152159        } 
     160 
    153161} 
    154  
    155162 
    156163class getHtmLawed extends AccessorAbstract 
    157164{ 
     165 
    158166        /** 
    159         * a function to filter HTML 
    160         * 
    161         * @return string 
    162         */ 
     167         * a function to filter HTML 
     168         * 
     169         * @return string 
     170         */ 
    163171        protected function inspekt($text) 
    164172        { 
    165                 /*  make_tag_strict is OFF because we don't want to convert <u>, etc. to css  
    166                         otherwise the strip_tags won't be able to allow them when requested in sanitize(). */ 
     173                // make_tag_strict is OFF because we don't want to convert <u>, etc. to CSS 
     174                // otherwise the strip_tags won't be able to allow them when requested in sanitize(). 
    167175                $config = array('safe' => 1, 'make_tag_strict' => 0); 
    168                  
    169                 // Allow plugins to alter the value of $config/ 
    170                 // Plugins should return an array, e.g. array('safe' => 1); 
    171                 /* 
    172                 require_once(BASE . 'Hotaru.php'); 
    173                 $h = new Hotaru(); 
    174                 $results = $h->pluginHook('hotaru_inspekt_htmlawed_config'); 
    175                 if (is_array($results)) { 
    176                         foreach ($results as $res) { 
    177                                 // THIS LOOKS WEIRD. IT NEEDS A RETHINK /Nick 
    178                                 $config = $res; // $config takes on the value returned from the last plugin using this hook. 
    179                         } 
    180                 } 
    181                 */ 
    182                  
    183                 require_once(EXTENSIONS . 'htmLawed/htmLawed.php'); 
    184                  
    185                 if (!get_magic_quotes_gpc()) { 
    186                         return htmLawed($text, $config); 
    187                 } 
    188                 else  
    189                 { 
    190                         return htmLawed(stripslashes($text), $config); 
    191                 } 
    192                 return false; 
     176                require_once EXTENSIONS.'htmlawed/htmlawed.php'; 
     177                $text = (!get_magic_quotes_gpc()) ? $text : stripslashes($text); 
     178                return htmLawed($text, $config); 
    193179        } 
     180 
    194181} 
    195  
    196 ?> 
  • branches/1.5/libs/Maintenance.php

    r2055 r2292  
    11<?php 
     2 
    23/** 
    34 * Functions for maintaining the health of Hotaru CMS 
     
    2627class Maintenance 
    2728{ 
    28         /**  
    29          * System Report is in libs/Debug.php  
    30          */ 
    31           
    32          
     29 
    3330        /** 
    3431         * Calls the delete_files function, then displays a message. 
     
    4138        { 
    4239                // clear language from memory (lang_cache only) 
    43                 if ($folder == 'lang_cache') { $h->lang = array(); } 
    44                  
     40                if ($folder == 'lang_cache') { 
     41                        $h->lang = array(); 
     42                } 
     43 
    4544                // go delete the files 
    46                 $success = $this->deleteFiles(CACHE . $folder); 
    47                  
     45                $success = $this->deleteFiles(CACHE.$folder); 
     46 
    4847                // lang_cache only: 
    49                 if ($folder == 'lang_cache') {  
     48                if ($folder == 'lang_cache') { 
    5049                        $langObj = new Language(); 
    5150                        $h->lang = $langObj->includeLanguagePack($h->lang, 'main'); 
    5251                        $h->lang = $langObj->includeLanguagePack($h->lang, 'admin'); 
    5352                } 
    54                  
     53 
    5554                // no need to show a message, return now 
    56                 if (!$msg) { return $success; } 
    57                  
     55                if (!$msg) { 
     56                        return $success; 
     57                } 
     58 
    5859                // prepare messages 
    5960                if ($success) { 
     
    6263                } else { 
    6364                        $h->message = $h->lang['admin_maintenance_clear_cache_failure']; 
    64                         $h->messageType = 'red';     
    65                 } 
    66                  
     65                        $h->messageType = 'red'; 
     66                } 
     67 
    6768                // return boolean result 
    6869                return $success; 
    6970        } 
    70          
    71          
     71 
    7272        /** 
    7373         * Remove plugin settings 
     
    7878        public function removeSettings($h, $folder, $msg = true) 
    7979        { 
    80                 if (!$folder) { $folder = $h->plugin->folder; } 
    81                 $sql = "DELETE FROM " . DB_PREFIX . "pluginsettings WHERE plugin_folder = %s"; 
     80                if (!$folder) { 
     81                        $folder = $h->plugin->folder; 
     82                } 
     83                $sql = "DELETE FROM ".TABLE_PLUGINSETTINGS."pluginsettings WHERE plugin_folder = %s"; 
    8284                $h->db->get_results($h->db->prepare($sql, $folder)); 
    83                  
     85 
    8486                if ($msg) { 
    8587                        $h->message = $h->lang['admin_maintenance_settings_removed']; 
     
    8789                } 
    8890        } 
    89          
    90          
     91 
    9192        /** 
    9293         * Deletes rows from pluginsettings that match a given setting or plugin 
     
    9899        { 
    99100                if ($setting) { 
    100                         $sql = "DELETE FROM " . TABLE_PLUGINSETTINGS . " WHERE plugin_setting = %s"; 
     101                        $sql = "DELETE FROM ".TABLE_PLUGINSETTINGS." WHERE plugin_setting = %s"; 
    101102                        $h->db->query($h->db->prepare($sql, $setting)); 
    102                 }  
    103                 elseif ($folder)  
    104                 { 
    105                         $sql = "DELETE FROM " . TABLE_PLUGINSETTINGS . " WHERE plugin_folder = %s"; 
     103                } elseif ($folder) { 
     104                        $sql = "DELETE FROM ".TABLE_PLUGINSETTINGS." WHERE plugin_folder = %s"; 
    106105                        $h->db->query($h->db->prepare($sql, $folder)); 
    107106                } 
    108                  
     107 
    109108                // optimize the table 
    110                 $h->db->query("OPTIMIZE TABLE " . TABLE_PLUGINSETTINGS); 
    111         } 
    112          
    113          
     109                $h->db->query("OPTIMIZE TABLE ".TABLE_PLUGINSETTINGS); 
     110        } 
     111 
    114112        /** 
    115113         * Delete all files in the specified directory except placeholder.txt 
     
    117115         * @param string $dir - path to the cache folder 
    118116         * @return bool 
    119          */     
     117         */ 
    120118        public function deleteFiles($dir) 
    121119        { 
    122                 $handle=opendir($dir); 
    123                  
     120                $handle = opendir($dir); 
     121 
    124122                $success = false; 
    125                 while (($file = readdir($handle))!==false) { 
    126                     if (is_file($dir.'/'.$file)) { 
    127                         if ($file != 'placeholder.txt') {  
    128                                 if (@unlink($dir.'/'.$file)) { 
    129                                         // ignore setting $success for the JavascriptConstants file which is ALWAYS present (even gets regenerated after deletion) 
    130                                         if ($file != 'JavascriptConstants.js') { $success = true; } 
    131                                 } else { 
    132                                         $success = false; 
     123                while (($file = readdir($handle)) !== false) { 
     124                        if (is_file($dir.'/'.$file)) { 
     125                                if ($file != 'placeholder.txt') { 
     126                                        if (@unlink($dir.'/'.$file)) { 
     127                                                // ignore setting $success for the JavascriptConstants file which is ALWAYS present (even gets regenerated after deletion) 
     128                                                if ($file != 'JavascriptConstants.js') { 
     129                                                        $success = true; 
     130                                                } 
     131                                        } else { 
     132                                                $success = false; 
     133                                        } 
    133134                                } 
    134135                        } 
    135                     } 
    136136                } 
    137137                closedir($handle); 
    138138                return $success; 
    139139        } 
    140          
    141          
     140 
    142141        /** 
    143142         * Optimize all database tables 
     
    146145        { 
    147146                $h->db->selectDB(DB_NAME); 
    148                  
    149                 foreach ( $h->db->get_col("SHOW TABLES",0) as $table_name ) 
    150                 { 
    151                         $h->db->query("OPTIMIZE TABLE " . $table_name); 
    152                 } 
    153                  
     147 
     148                foreach ($h->db->get_col("SHOW TABLES", 0) as $table_name) { 
     149                        $h->db->query("OPTIMIZE TABLE ".$table_name); 
     150                } 
     151 
    154152                $h->message = $h->lang['admin_maintenance_optimize_success']; 
    155153                $h->messageType = 'green'; 
    156154        } 
    157          
    158          
     155 
    159156        /** 
    160157         * Empty plugin database table 
     
    165162        public function emptyTable($h, $table_name, $msg = true) 
    166163        { 
    167                 $h->db->query("DELETE FROM " . $table_name); 
    168                  
     164                $h->db->query("DELETE FROM ".$table_name); 
     165 
    169166                if ($msg) { 
    170167                        $h->message = $h->lang['admin_maintenance_table_emptied']; 
     
    172169                } 
    173170        } 
    174          
    175          
     171 
    176172        /** 
    177173         * Delete plugin database table 
     
    181177        public function dropTable($h, $table_name, $msg = true) 
    182178        { 
    183                 $h->db->query("DROP TABLE " . $table_name); 
    184                  
     179                $h->db->query("DROP TABLE ".$table_name); 
     180 
    185181                if ($msg) { 
    186182                        $h->message = $h->lang['admin_maintenance_table_deleted']; 
     
    188184                } 
    189185        } 
    190          
    191          
     186 
    192187        /** 
    193188         * Open or close the site for maintenance 
     
    198193        public function openCloseSite($h, $switch = 'open') 
    199194        { 
    200                 if ($switch == 'open') {  
     195                if ($switch == 'open') { 
    201196                        // open 
    202                         $sql = "UPDATE " . TABLE_SETTINGS . " SET settings_value = %s WHERE settings_name = %s"; 
     197                        $sql = "UPDATE ".TABLE_SETTINGS." SET settings_value = %s WHERE settings_name = %s"; 
    203198                        $h->db->query($h->db->prepare($sql, 'true', 'SITE_OPEN')); 
    204199                        $h->message = $h->lang['admin_maintenance_site_opened']; 
     
    206201                } else { 
    207202                        //close 
    208                         $sql = "UPDATE " . TABLE_SETTINGS . " SET settings_value = %s WHERE settings_name = %s"; 
     203                        $sql = "UPDATE ".TABLE_SETTINGS." SET settings_value = %s WHERE settings_name = %s"; 
    209204                        $h->db->query($h->db->prepare($sql, 'false', 'SITE_OPEN')); 
    210205                        $h->message = $h->lang['admin_maintenance_site_closed']; 
     
    212207                } 
    213208        } 
    214          
    215          
     209 
    216210        /** 
    217211         * Site closed: Exit 
     
    225219 
    226220                // include current theme style and default style 
    227                 if (file_exists(BASE . 'content/themes/' . $h->pageHandling->default . 'css/style.css')) { 
    228                         echo "<link rel='stylesheet' href='" . SITEURL . "content/themes/" . $h->pageHandling->default . "css/style.css' type='text/css'>\n"; 
    229                 } 
    230                 if (file_exists(BASE . 'content/themes/' . THEME . 'css/style.css')) { 
    231                         echo "<link rel='stylesheet' href='" . SITEURL . "content/themes/" . THEME . "css/style.css' type='text/css'>\n"; 
     221                if (file_exists(BASE.'content/themes/'.$h->pageHandling->default.'css/style.css')) { 
     222                        echo "<link rel='stylesheet' href='".SITEURL."content/themes/".$h->pageHandling->default."css/style.css' type='text/css'>\n"; 
     223                } 
     224                if (file_exists(BASE.'content/themes/'.THEME.'css/style.css')) { 
     225                        echo "<link rel='stylesheet' href='".SITEURL."content/themes/".THEME."css/style.css' type='text/css'>\n"; 
    232226                } 
    233227                echo "</HEAD>\n<BODY>\n"; 
    234228                echo "<div id='site_closed'>\n"; 
    235                  
     229 
    236230                // show custom maintenance page if one exists: 
    237                 if (file_exists(THEMES . THEME . 'closed.php')) 
    238                 { 
     231                if (file_exists(THEMES.THEME.'closed.php')) { 
    239232                        $h->displayTemplate('closed'); 
    240                 }  
    241                 else 
    242                 { 
     233                } else { 
    243234                        // show default maintenance page: 
    244235                        echo $lang['main_hotaru_site_closed']; 
    245                         echo "<br /><span id='site_closed_admin_link'>[<a href='" . SITEURL . "admin_index.php?page=admin_login'>Admin Login</a>]</span>"; 
    246                 } 
    247                  
     236                        echo "<br /><span id='site_closed_admin_link'>[<a href='".SITEURL."admin_index.php?page=admin_login'>Admin Login</a>]</span>"; 
     237                } 
     238 
    248239                echo "\n</div>\n</BODY>\n</HTML>\n"; 
    249                  
    250                 die(); exit; 
    251         } 
    252          
    253          
     240 
     241                die(); 
     242                exit; 
     243        } 
     244 
    254245        /** 
    255246         * Get Site Annoucement for Maintenance Page (AdminPages.php) 
     
    258249        { 
    259250                // get announcement from database 
    260                 $sql = "SELECT miscdata_value FROM " . TABLE_MISCDATA ." WHERE miscdata_key = %s"; 
     251                $sql = "SELECT miscdata_value FROM ".TABLE_MISCDATA." WHERE miscdata_key = %s"; 
    261252                $query = $h->db->prepare($sql, 'site_announcement'); 
    262                  
     253 
    263254                if ($h->pageName != 'maintenance') { 
    264255                        $h->smartCache('on', 'miscdata', 60, $query); // start using cache 
    265256                } 
    266                  
     257 
    267258                $result = $h->db->get_var($query); 
    268                  
     259 
    269260                if ($h->pageName != 'maintenance') { 
    270261                        $h->smartCache('off'); // stop using cache  
    271262                } 
    272                  
     263 
    273264                // assign results to $h 
    274265                if ($result) { 
     
    280271                        $h->vars['admin_announcement_enabled'] = ""; 
    281272                } 
    282                  
    283         } 
    284          
    285          
     273        } 
     274 
    286275        /** 
    287276         * Add Site Annoucement from Maintenance Page (AdminPages.php) 
     
    298287                        $h->vars['admin_announcement_enabled'] = ""; 
    299288                } 
    300                  
     289 
    301290                // prepare annoucment for database entry: 
    302                 $value = array('announcement'=>urlencode($h->vars['admin_announcement']), 'enabled'=>$h->vars['admin_announcement_enabled']); 
     291                $value = array('announcement' => urlencode($h->vars['admin_announcement']), 'enabled' => $h->vars['admin_announcement_enabled']); 
    303292                $value = serialize($value); 
    304                  
     293 
    305294                // update existing db record 
    306                 $sql = "UPDATE " . TABLE_MISCDATA . " SET miscdata_value = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
     295                $sql = "UPDATE ".TABLE_MISCDATA." SET miscdata_value = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
    307296                $h->db->query($h->db->prepare($sql, $value, $h->currentUser->id, 'site_announcement')); 
    308                  
     297 
    309298                // clear the database cache: 
    310299                $h->clearCache('db_cache', false); 
    311                  
     300 
    312301                $h->message = $h->lang['admin_maintenance_announcement_updated']; 
    313302                $h->messageType = 'green'; 
    314303        } 
    315          
    316          
     304 
    317305        /** 
    318306         * Get all files in the specified directory except placeholder.txt 
     
    321309         * @param array $exclude - array of file/folder names to exclude 
    322310         * @return array 
    323          */     
     311         */ 
    324312        public function getFiles($dir, $exclude = array()) 
    325313        { 
     
    327315                $exceptions = array('.svn', '.', '..', 'placeholder.txt'); 
    328316                $exceptions = array_merge($exceptions, $exclude); 
    329                  
    330                 $handle=opendir($dir); 
    331                  
    332                 while (($file = readdir($handle))!==false) { 
     317 
     318                $handle = opendir($dir); 
     319 
     320                while (($file = readdir($handle)) !== false) { 
    333321                        if (!in_array($file, $exceptions)) { 
    334322                                array_push($files, $file); 
     
    336324                } 
    337325                closedir($handle); 
    338                  
    339                 if ($files) { return $files; } else { return false; } 
    340         } 
     326 
     327                if ($files) { 
     328                        return $files; 
     329                } 
     330                return false; 
     331        } 
     332 
    341333} 
    342 ?> 
  • branches/1.5/libs/PageHandling.php

    r2273 r2292  
    115115                } 
    116116 
    117                 return (bool) ($real_page == $page); 
     117                return (bool) ($real_page === $page); 
    118118        } 
    119119 
  • branches/1.5/libs/ThemeSettings.php

    r1662 r2292  
    11<?php 
     2 
    23/** 
    34 * Theme Settings 
     
    2627class ThemeSettings 
    2728{ 
     29 
    2830        /** 
    2931         * Read and return plugin info from top of a plugin file. 
     
    3436        public function readThemeMeta($h, $theme = 'default') 
    3537        { 
    36                 if (!$theme) { $theme = rtrim(THEME, '/'); } 
    37                  
     38                if (!$theme) { 
     39                        $theme = rtrim(THEME, '/'); 
     40                } 
     41 
    3842                // Include the generic_pmd class that reads post metadata from the a plugin 
    39                 require_once(EXTENSIONS . 'GenericPHPConfig/class.metadata.php'); 
     43                require_once(EXTENSIONS.'GenericPHPConfig/class.metadata.php'); 
    4044                $metaReader = new generic_pmd(); 
    41                 $plugin_metadata = $metaReader->read(THEMES . $theme . '/index.php'); 
    42                  
    43                 if ($plugin_metadata) { return $plugin_metadata; } else { return false; } 
     45                $plugin_metadata = $metaReader->read(THEMES.$theme.'/index.php'); 
     46 
     47                if ($plugin_metadata) { 
     48                        return $plugin_metadata; 
     49                } else { 
     50                        return false; 
     51                } 
    4452        } 
    45          
    46          
     53 
    4754        /** 
    4855         * Get and unserialize serialized settings 
     
    5461        public function getThemeSettings($h, $theme = '', $return = 'value') 
    5562        { 
    56                 if (!$theme) { $theme = rtrim(THEME, '/'); } 
    57                  
     63                if (!$theme) { 
     64                        $theme = rtrim(THEME, '/'); 
     65                } 
     66 
    5867                // Get settings from the database if they exist... 
    59                 $sql = "SELECT miscdata_value, miscdata_default FROM " . TABLE_MISCDATA . " WHERE miscdata_key = %s"; 
    60                 $settings = $h->db->get_row($h->db->prepare($sql, $theme . '_settings')); 
    61                 if (!$settings) { return false; }  
    62                  
     68                $sql = "SELECT miscdata_value, miscdata_default FROM ".TABLE_MISCDATA." WHERE miscdata_key = %s"; 
     69                $settings = $h->db->get_row($h->db->prepare($sql, $theme.'_settings')); 
     70                if (!$settings) { 
     71                        return false; 
     72                } 
     73 
    6374                if ($return == 'value') { 
    6475                        $settings = unserialize($settings->miscdata_value); 
    65                 } else {  
     76                } else { 
    6677                        $settings = unserialize($settings->miscdata_default); 
    6778                } 
    68                  
    69                 if ($settings) { return $settings; } else { return false; }  
     79 
     80                if ($settings) { 
     81                        return $settings; 
     82                } 
     83                return FALSE; 
    7084        } 
    71          
    72          
     85 
    7386        /** 
    7487         * Update theme settings 
     
    7790         * @param string $theme theme folder name 
    7891         * @param string $column 'value', 'default' or 'both' 
    79          
     92 
    8093         */ 
    8194        public function updateThemeSettings($h, $settings = array(), $theme = '', $column = 'value') 
    8295        { 
    83                 if (!$theme) { $theme = rtrim(THEME, '/'); } 
    84                  
     96                if (!$theme) { 
     97                        $theme = rtrim(THEME, '/'); 
     98                } 
     99 
    85100                $settings = serialize($settings); 
    86                 if (isset($h->currentUser->id)) { $updateby = $h->currentUser->id; } else { $updateby = 1; } 
    87                  
     101                $updateby = (isset($h->currentUser->id)) ? $h->currentUser->id : 1; 
    88102                $exists = $h->getThemeSettings($theme); 
    89                 if (!$exists)  
    90                 { 
    91                         $sql = "INSERT INTO " . TABLE_MISCDATA . " (miscdata_key, miscdata_value, miscdata_default, miscdata_updateby) VALUES (%s, %s, %s, %d)"; 
    92                         $h->db->query($h->db->prepare($sql, $theme . '_settings', $settings, $settings, $updateby)); 
    93                 }  
    94                 else  
    95                 { 
     103 
     104                if (!$exists) { 
     105                        $sql = "INSERT INTO ".TABLE_MISCDATA." (miscdata_key, miscdata_value, miscdata_default, miscdata_updateby) VALUES (%s, %s, %s, %d)"; 
     106                        $h->db->query($h->db->prepare($sql, $theme.'_settings', $settings, $settings, $updateby)); 
     107                } else { 
    96108                        switch ($column) { 
    97109                                case 'default': 
    98                                         $sql = "UPDATE " . TABLE_MISCDATA . " SET miscdata_default = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
    99                                         $h->db->query($h->db->prepare($sql, $settings, $updateby, $theme . '_settings')); 
     110                                        $sql = "UPDATE ".TABLE_MISCDATA." SET miscdata_default = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
     111                                        $h->db->query($h->db->prepare($sql, $settings, $updateby, $theme.'_settings')); 
    100112                                        break; 
    101113                                case 'both': 
    102                                         $sql = "UPDATE " . TABLE_MISCDATA . " SET miscdata_value = %s, miscdata_default = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
    103                                         $h->db->query($h->db->prepare($sql, $settings, $settings, $updateby, $theme . '_settings')); 
     114                                        $sql = "UPDATE ".TABLE_MISCDATA." SET miscdata_value = %s, miscdata_default = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
     115                                        $h->db->query($h->db->prepare($sql, $settings, $settings, $updateby, $theme.'_settings')); 
    104116                                default: 
    105                                         $sql = "UPDATE " . TABLE_MISCDATA . " SET miscdata_value = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
    106                                         $h->db->query($h->db->prepare($sql, $settings, $updateby, $theme . '_settings')); 
     117                                        $sql = "UPDATE ".TABLE_MISCDATA." SET miscdata_value = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
     118                                        $h->db->query($h->db->prepare($sql, $settings, $updateby, $theme.'_settings')); 
    107119                        } 
    108120                } 
    109                  
    110121                // optimize the table 
    111                 $h->db->query("OPTIMIZE TABLE " . TABLE_MISCDATA); 
     122                $h->db->query("OPTIMIZE TABLE ".TABLE_MISCDATA); 
    112123        } 
    113124} 
    114 ?> 
  • branches/1.5/libs/UserBase.php

    r2162 r2292  
    11<?php 
     2 
    23/** 
    34 * Base User functions for basic info, settings and permissions 
     
    2627class UserBase 
    2728{ 
    28         protected $id           = 0; 
    29         protected $name         = ''; 
    30         protected $role         = 'member'; 
    31         protected $password     = 'password'; 
    32         protected $email        = ''; 
    33         protected $emailValid   = 0; 
    34         protected $loggedIn     = false; 
    35         protected $perms        = array();  // permissions 
    36         protected $settings     = array();  // settings 
    37         protected $profile      = array();  // profile 
    38         protected $ip           = 0; 
     29 
     30        protected $id = 0; 
     31        protected $name = ''; 
     32        protected $role = 'member'; 
     33        protected $password = 'password'; 
     34        protected $email = ''; 
     35        protected $emailValid = 0; 
     36        protected $loggedIn = false; 
     37        protected $perms = array();  // permissions 
     38        protected $settings = array();  // settings 
     39        protected $profile = array();  // profile 
     40        protected $ip = 0; 
    3941        protected $lastActivity = 0; 
    4042 
    41          
    4243        /** 
    4344         * Access modifier to set protected properties 
     
    4546        public function __set($var, $val) 
    4647        { 
    47                 $this->$var = $val;   
    48         } 
    49          
    50          
     48                $this->$var = $val; 
     49        } 
     50 
    5151        /** 
    5252         * Access modifier to get protected properties 
     
    5656                return $this->$var; 
    5757        } 
    58          
    59          
     58 
    6059        /** 
    6160         * Set permission  
     
    7372                $this->perms[$perm_name] = $setting; 
    7473        } 
    75          
    76          
     74 
    7775        /** 
    7876         * Set ALL permissions  
     
    8684                } 
    8785        } 
    88          
    89          
     86 
    9087        /** 
    9188         * Get permission  
     
    9693        public function getPermission($perm_name) 
    9794        { 
    98                 if (isset($this->perms[$perm_name])) {  
     95                if (isset($this->perms[$perm_name])) { 
    9996                        return $this->perms[$perm_name]; 
    10097                } 
    10198                return FALSE; 
    10299        } 
    103          
    104          
     100 
    105101        /** 
    106102         * Get ALL permissions (serialized) 
     
    112108                return $this->perms; 
    113109        } 
    114          
    115          
     110 
    116111        /** 
    117112         * Get basic user details 
     
    123118         * 
    124119         * Note: Needs either userid or username, not both 
    125          */     
     120         */ 
    126121        public function getUserBasic($h, $userid = 0, $username = '', $no_cache = false) 
    127122        { 
    128123                // Prepare SQL 
    129                 if ($userid != 0){              // use userid 
     124                if ($userid != 0) {                       // use userid 
    130125                        $where = "user_id = %d"; 
    131126                        $param = $userid; 
    132                 } elseif ($username != '') {    // use username 
     127                } elseif ($username != '') {    // use username 
    133128                        $where = "user_username = %s"; 
    134129                        $param = $username; 
     
    136131                        return FALSE; 
    137132                } 
    138                  
     133 
    139134                // Build SQL 
    140                 $query = "SELECT user_id, user_username, user_password, user_role, user_email, user_email_valid, user_ip, user_permissions FROM " . TABLE_USERS . " WHERE " . $where; 
     135                $query = "SELECT user_id, user_username, user_password, user_role, user_email, user_email_valid, user_ip, user_permissions FROM ".TABLE_USERS." WHERE ".$where; 
    141136                $sql = $h->db->prepare($query, $param); 
    142                  
    143                 if (!isset($h->vars['tempUserCache'])) { $h->vars['tempUserCache'] = array(); } 
    144                  
     137 
     138                if (!isset($h->vars['tempUserCache'])) { 
     139                        $h->vars['tempUserCache'] = array(); 
     140                } 
     141 
    145142                // If this query has already been read once this page load, we should have it in memory... 
    146143                if (!$no_cache && array_key_exists($sql, $h->vars['tempUserCache'])) { 
     
    152149                        $h->vars['tempUserCache'][$sql] = $user_info; 
    153150                } 
    154                  
    155                 if (!$user_info) { return false; } 
    156                  
     151 
     152                if (!$user_info) { 
     153                        return false; 
     154                } 
     155 
    157156                $this->id = $user_info->user_id; 
    158157                $this->name = $user_info->user_username; 
     
    162161                $this->emailValid = $user_info->user_email_valid; 
    163162                $this->ip = $user_info->user_ip; 
    164                  
     163 
    165164                return $user_info; 
    166165        } 
    167          
    168          
     166 
    169167        /** 
    170168         * Get full user details (i.e. permissions and settings, too) 
     
    176174         * 
    177175         * Note: Needs either userid or username, not both 
    178          */     
     176         */ 
    179177        public function getUser($h, $userid = 0, $username = '', $no_cache = false) 
    180178        { 
    181179                $user_info = $this->getUserBasic($h, $userid, $username, $no_cache); 
    182                 if (!$user_info) { return false; } 
    183                  
     180                if (!$user_info) { 
     181                        return false; 
     182                } 
     183 
    184184                // If a new plugin is installed, we need a way of adding any new default permissions 
    185185                // that plugin provides. So, we get all defaults, then overwrite with existing perms. 
    186                  
    187186                // get default permissions for the site 
    188187                $default_perms = $this->getDefaultPermissions($h, $this->role); 
    189                  
    190                 // get existing permissions for the user                 
     188 
     189                // get existing permissions for the user 
    191190                $existing_perms = unserialize($user_info->user_permissions); 
    192                  
     191 
    193192                // merge permissions 
    194                 if (!$default_perms) { $default_perms = array(); } 
    195                 if (!$existing_perms) { $existing_perms = array(); } 
     193                if (!$default_perms) { 
     194                        $default_perms = array(); 
     195                } 
     196                if (!$existing_perms) { 
     197                        $existing_perms = array(); 
     198                } 
    196199                $updated_perms = array_merge($default_perms, $existing_perms); 
    197                  
     200 
    198201                $this->setAllPermissions($updated_perms); 
    199202                $user_info->user_permissions = serialize($updated_perms);   // update $user_info 
    200                  
    201203                // get user settings: 
    202204                $this->settings = $this->getProfileSettingsData($h, 'user_settings', $this->id); 
    203205                $user_info->user_settings = $this->settings;   // update $user_info 
    204                  
     206 
    205207                return $user_info; 
    206208        } 
    207          
    208          
     209 
    209210        /** 
    210211         * Add a new user 
     
    214215                // get default permissions 
    215216                $permissions = $this->getDefaultPermissions($h, $this->role); 
    216                  
     217 
    217218                // get user ip 
    218219                $userip = $h->cage->server->testIp('REMOTE_ADDR'); 
    219                  
     220 
    220221                // add user to the database 
    221                 $sql = "INSERT INTO " . TABLE_USERS . " (user_username, user_role, user_date, user_password, user_email, user_permissions, user_ip) VALUES (%s, %s, CURRENT_TIMESTAMP, %s, %s, %s, %s)"; 
     222                $sql = "INSERT INTO ".TABLE_USERS." (user_username, user_role, user_date, user_password, user_email, user_permissions, user_ip) VALUES (%s, %s, CURRENT_TIMESTAMP, %s, %s, %s, %s)"; 
    222223                $h->db->query($h->db->prepare($sql, $this->name, $this->role, $this->password, $this->email, serialize($permissions), $userip)); 
    223224        } 
    224          
    225          
     225 
    226226        /** 
    227227         * Update a user 
     
    231231                //determine if the current user is the same as this object's user 
    232232                $updatedby = ($userid != $this->id) ? $userid : $this->id; 
    233                  
     233 
    234234                if ($this->id != 0) { 
    235                         $sql = "UPDATE " . TABLE_USERS . " SET user_username = %s, user_role = %s, user_password = %s, user_email = %s, user_permissions = %s, user_ip = %s, user_updateby = %d WHERE user_id = %d"; 
     235                        $sql = "UPDATE ".TABLE_USERS." SET user_username = %s, user_role = %s, user_password = %s, user_email = %s, user_permissions = %s, user_ip = %s, user_updateby = %d WHERE user_id = %d"; 
    236236                        $h->db->query($h->db->prepare($sql, $this->name, $this->role, $this->password, $this->email, serialize($this->getAllPermissions()), $this->ip, $updatedby, $this->id)); 
    237237                        return TRUE; 
     
    240240                return FALSE; 
    241241        } 
    242          
    243          
     242 
    244243        /** 
    245244         * Physically delete this user 
     
    248247         * @param array $user_id (optional) 
    249248         */ 
    250         public function deleteUser($h, $user_id = 0)  
    251         { 
    252                 if (!$user_id) { $user_id = $this->id; } 
    253                  
    254                 $h->pluginHook('userbase_delete_user', '', array('user_id'=>$user_id)); 
    255                  
    256                 $sql = "DELETE FROM " . TABLE_USERS . " WHERE user_id = %d"; 
     249        public function deleteUser($h, $user_id = 0) 
     250        { 
     251                if (!$user_id) { 
     252                        $user_id = $this->id; 
     253                } 
     254 
     255                $h->pluginHook('userbase_delete_user', '', array('user_id' => $user_id)); 
     256 
     257                $sql = "DELETE FROM ".TABLE_USERS." WHERE user_id = %d"; 
    257258                $h->db->query($h->db->prepare($sql, $user_id)); 
    258                  
    259                 $sql = "DELETE FROM " . TABLE_USERMETA . " WHERE usermeta_userid = %d"; 
     259 
     260                $sql = "DELETE FROM ".TABLE_USERMETA." WHERE usermeta_userid = %d"; 
    260261                $h->db->query($h->db->prepare($sql, $user_id)); 
    261262        } 
    262  
    263263 
    264264        /** 
     
    270270         * @return array $perms 
    271271         */ 
    272         public function getDefaultPermissions($h, $role = '', $defaults = 'site', $options_only = false)  
     272        public function getDefaultPermissions($h, $role = '', $defaults = 'site', $options_only = false) 
    273273        { 
    274274                $perms = array(); // to be filled with default permissions for this user 
    275                  
    276275                // get site or base permissions (i.e. the originals) 
    277                 $field = ($defaults == 'site') ? 'miscdata_value':'miscdata_default'; 
    278                  
     276                $field = ($defaults == 'site') ? 'miscdata_value' : 'miscdata_default'; 
     277 
    279278                // get default permissions from the database: 
    280                 $query = "SELECT " . $field . " FROM " . TABLE_MISCDATA . " WHERE miscdata_key = %s LIMIT 1"; 
     279                $query = "SELECT ".$field." FROM ".TABLE_MISCDATA." WHERE miscdata_key = %s LIMIT 1"; 
    281280                $sql = $h->db->prepare($query, 'permissions'); 
    282                  
     281 
    283282                // Create temp cache array 
    284                 if (!isset($h->vars['tempPermissionsCache'])) { $h->vars['tempPermissionsCache'] = array(); } 
    285                  
     283                if (!isset($h->vars['tempPermissionsCache'])) { 
     284                        $h->vars['tempPermissionsCache'] = array(); 
     285                } 
     286 
    286287                // If this query has already been read once this page load, we should have it in memory... 
    287288                if (array_key_exists($sql, $h->vars['tempPermissionsCache'])) { 
     
    293294                        $h->vars['tempPermissionsCache'][$sql] = $db_perms; 
    294295                } 
    295                  
     296 
    296297                $permissions = unserialize($db_perms); 
    297                  
     298 
    298299                if (!$permissions) { 
    299300                        // must return an empty array for array_merge, not false. 
    300301                        return array(); 
    301302                } 
    302                  
     303 
    303304                if ($options_only) { 
    304305                        // the editPermissions function in the Users plugin needs these  
    305                         return $permissions['options'];  
    306                 } 
    307                  
     306                        return $permissions['options']; 
     307                } 
     308 
    308309                if ($role == 'all') { 
    309310                        // plugins need all permissions and options when installed 
    310311                        return $permissions; 
    311312                } 
    312                  
     313 
    313314                unset($permissions['options']); // don't need the options anymore 
    314                  
    315                 foreach ($permissions as $perm => $roles) {  
     315 
     316                foreach ($permissions as $perm => $roles) { 
    316317                        if (isset($roles[$role])) { 
    317318                                $perms[$perm] = $roles[$role];  // perm for this role 
     
    320321                        } 
    321322                } 
    322                  
     323 
    323324                return $perms; 
    324325        } 
    325          
    326          
     326 
    327327        /** 
    328328         * Update Default permissions 
     
    332332         * @param bool $remove - false if adding perms, true if deleting them 
    333333         */ 
    334         public function updateDefaultPermissions($h, $new_perms = array(), $defaults = 'both', $remove = false)  
    335         { 
    336                 if (!$new_perms) { return false; } 
    337                  
     334        public function updateDefaultPermissions($h, $new_perms = array(), $defaults = 'both', $remove = false) 
     335        { 
     336                if (!$new_perms) { 
     337                        return false; 
     338                } 
     339 
    338340                // get and merge permissions 
    339                 if ($defaults == 'site') 
    340                 { 
     341                if ($defaults == 'site') { 
    341342                        if ($remove) { 
    342343                                $site_perms = $new_perms; 
    343344                        } else { 
    344                                 $site_perms = $this->getDefaultPermissions($h,'all', 'site'); //get site defaults 
     345                                $site_perms = $this->getDefaultPermissions($h, 'all', 'site'); //get site defaults 
    345346                                $site_perms = array_merge_recursive($site_perms, $new_perms); // merge 
    346347                        } 
    347                         $sql = "UPDATE " . TABLE_MISCDATA . " SET miscdata_value = %s WHERE miscdata_key = %s"; 
     348                        $sql = "UPDATE ".TABLE_MISCDATA." SET miscdata_value = %s WHERE miscdata_key = %s"; 
    348349                        $h->db->query($h->db->prepare($sql, serialize($site_perms), 'permissions')); 
    349                 }  
    350                 elseif ($defaults == 'base') 
    351                 { 
     350                } elseif ($defaults == 'base') { 
    352351                        if ($remove) { 
    353352                                $base_perms = $new_perms; 
    354353                        } else { 
    355                                 $base_perms = $this->getDefaultPermissions($h,'all', 'base'); // get base defaults 
     354                                $base_perms = $this->getDefaultPermissions($h, 'all', 'base'); // get base defaults 
    356355                                $base_perms = array_merge_recursive($base_perms, $new_perms); // merge 
    357356                        } 
    358                         $sql = "UPDATE " . TABLE_MISCDATA . " SET miscdata_default = %s WHERE miscdata_key = %s"; 
     357                        $sql = "UPDATE ".TABLE_MISCDATA." SET miscdata_default = %s WHERE miscdata_key = %s"; 
    359358                        $h->db->query($h->db->prepare($sql, serialize($base_perms), 'permissions')); 
    360                 } 
    361                 else  
    362                 { 
     359                } else { 
    363360                        if ($remove) { 
    364361                                $site_perms = $new_perms; 
    365362                                $base_perms = $new_perms; 
    366363                        } else { 
    367                                 $site_perms = $this->getDefaultPermissions($h,'all', 'site'); //get site defaults 
     364                                $site_perms = $this->getDefaultPermissions($h, 'all', 'site'); //get site defaults 
    368365                                $site_perms = array_merge_recursive($site_perms, $new_perms); // merge 
    369                                 $base_perms = $this->getDefaultPermissions($h,'all', 'base'); // get base defaults 
     366                                $base_perms = $this->getDefaultPermissions($h, 'all', 'base'); // get base defaults 
    370367                                $base_perms = array_merge_recursive($base_perms, $new_perms); // merge 
    371368                        } 
    372                         $sql = "UPDATE " . TABLE_MISCDATA . " SET miscdata_value = %s, miscdata_default = %s WHERE miscdata_key = %s"; 
     369                        $sql = "UPDATE ".TABLE_MISCDATA." SET miscdata_value = %s, miscdata_default = %s WHERE miscdata_key = %s"; 
    373370                        $h->db->query($h->db->prepare($sql, serialize($site_perms), serialize($base_perms), 'permissions')); 
    374371                } 
    375372        } 
    376          
    377          
     373 
    378374        /** 
    379375         * update permissions in the database 
     
    383379        public function updatePermissions($h) 
    384380        { 
    385                 $sql = "UPDATE " . TABLE_USERS . " SET user_permissions = %s WHERE user_id = %d"; 
     381                $sql = "UPDATE ".TABLE_USERS." SET user_permissions = %s WHERE user_id = %d"; 
    386382                $h->db->query($h->db->prepare($sql, serialize($this->getAllPermissions()), $this->id)); 
    387                  
     383 
    388384                // for undermods and above, set their emailValid to true when updating permissions or changing role 
    389385                $safe_array = array('undermod', 'member', 'moderator', 'supermod', 'admin'); 
    390386                if (!$this->emailValid && in_array($this->role, $safe_array)) { 
    391                         $sql = "UPDATE " . TABLE_USERS . " SET user_email_valid = %d WHERE user_id = %d"; 
     387                        $sql = "UPDATE ".TABLE_USERS." SET user_email_valid = %d WHERE user_id = %d"; 
    392388                        $h->db->query($h->db->prepare($sql, 1, $this->id)); 
    393389                } 
    394390        } 
    395                  
    396                  
    397         /** 
    398         * Get a user's profile or settings data 
    399         * 
    400         * @return array|false 
    401         */ 
     391 
     392        /** 
     393         * Get a user's profile or settings data 
     394         * 
     395         * @return array|false 
     396         */ 
    402397        public function getProfileSettingsData($h, $type = 'user_profile', $userid = 0, $check_exists_only = false) 
    403398        { 
    404                 if (!$userid) { $userid = $this->id; } 
    405                  
    406                 $query = "SELECT usermeta_value FROM " . DB_PREFIX . "usermeta WHERE usermeta_userid = %d AND usermeta_key = %s LIMIT 1"; 
     399                if (!$userid) { 
     400                        $userid = $this->id; 
     401                } 
     402 
     403                $query = "SELECT usermeta_value FROM ".TABLE_USERMETA." WHERE usermeta_userid = %d AND usermeta_key = %s LIMIT 1"; 
    407404                $sql = $h->db->prepare($query, $userid, $type); 
    408                  
    409                 if (isset($h->vars[$sql])) {  
    410                         $result = $h->vars[$sql];  
     405 
     406                if (isset($h->vars[$sql])) { 
     407                        $result = $h->vars[$sql]; 
    411408                } else { 
    412409                        $h->smartCache('on', 'usermeta', 60, $sql); // start using database cache 
    413410                        $result = $h->db->get_var($sql); 
    414                         $h->vars[$sql] = $result;    // cache result in memory (saves for just this page load) 
     411                        $h->vars[$sql] = $result;       // cache result in memory (saves for just this page load) 
    415412                        $h->smartCache('off'); // stop using database cache 
    416413                } 
    417                  
     414 
    418415                // if we're only testing to see if the settings exist, return here: 
    419                 if($check_exists_only && $result) { return true; } 
    420                 if($check_exists_only && !$result) { return false; } 
    421                  
    422                 if ($result) {  
     416                if ($check_exists_only && $result) { 
     417                        return true; 
     418                } 
     419                if ($check_exists_only && !$result) { 
     420                        return false; 
     421                } 
     422 
     423                if ($result) { 
    423424                        $result = unserialize($result); 
    424425                        if ($type == 'user_settings') { 
     
    433434                        return false; 
    434435                } 
    435                  
    436                 return $result;  
    437         } 
    438          
    439          
     436 
     437                return $result; 
     438        } 
     439 
    440440        /** 
    441441         * Save a user's profile or settings data 
     
    445445        public function saveProfileSettingsData($h, $data = array(), $type = 'user_profile', $userid = 0) 
    446446        { 
    447                 if (!$data) { return false; } 
    448                 if (!$userid) { $userid = $this->id; } 
    449                  
     447                if (!$data) { 
     448                        return false; 
     449                } 
     450                if (!$userid) { 
     451                        $userid = $this->id; 
     452                } 
     453 
    450454                $result = $h->getProfileSettingsData($type, $userid, true); 
    451                  
     455 
    452456                if (!$result) { 
    453                         $sql = "INSERT INTO " . TABLE_USERMETA . " (usermeta_userid, usermeta_key, usermeta_value, usermeta_updateby) VALUES(%d, %s, %s, %d)"; 
     457                        $sql = "INSERT INTO ".TABLE_USERMETA." (usermeta_userid, usermeta_key, usermeta_value, usermeta_updateby) VALUES(%d, %s, %s, %d)"; 
    454458                        $h->db->get_row($h->db->prepare($sql, $userid, $type, serialize($data), $h->currentUser->id)); 
    455459                } else { 
    456                         $sql = "UPDATE " . TABLE_USERMETA . " SET usermeta_value = %s, usermeta_updateby = %d WHERE usermeta_userid = %d AND usermeta_key = %s"; 
     460                        $sql = "UPDATE ".TABLE_USERMETA." SET usermeta_value = %s, usermeta_updateby = %d WHERE usermeta_userid = %d AND usermeta_key = %s"; 
    457461                        $h->db->get_row($h->db->prepare($sql, serialize($data), $h->currentUser->id, $userid, $type)); 
    458462                } 
    459                  
     463 
    460464                return true; 
    461465        } 
    462          
    463          
     466 
    464467        /** 
    465468         * Get the default user settings 
     
    470473        public function getDefaultSettings($h, $type = 'site') 
    471474        { 
    472                 if ($type == 'site') {  
    473                         $field = 'miscdata_value';  
    474                 } elseif ($type == 'base') {  
     475                if ($type == 'site') { 
     476                        $field = 'miscdata_value'; 
     477                } elseif ($type == 'base') { 
    475478                        $field = 'miscdata_default'; 
    476                 } else {  
    477                         return false; 
    478                 } 
    479                  
    480                 $query = "SELECT " . $field . " FROM " . TABLE_MISCDATA . " WHERE miscdata_key = %s LIMIT 1"; 
     479                } else { 
     480                        return false; 
     481                } 
     482 
     483                $query = "SELECT ".$field." FROM ".TABLE_MISCDATA." WHERE miscdata_key = %s LIMIT 1"; 
    481484                $sql = $h->db->prepare($query, 'user_settings'); 
    482                  
    483                 if (isset($h->vars['default_user_settings'][$sql])) {  
    484                         $result = $h->vars['default_user_settings'][$sql];  
     485 
     486                if (isset($h->vars['default_user_settings'][$sql])) { 
     487                        $result = $h->vars['default_user_settings'][$sql]; 
    485488                } else { 
    486489                        $h->smartCache('on', 'miscdata', 60, $sql); // start using database cache 
     
    489492                        $h->smartCache('off'); // stop using database cache 
    490493                } 
    491                  
     494 
    492495                if ($result) { 
    493496                        return unserialize($result); 
    494                 } else { 
    495                         return false; 
    496                 } 
    497         } 
    498          
    499          
     497                } 
     498                return false; 
     499        } 
     500 
    500501        /** 
    501502         * Update the default user settings 
     
    507508        public function updateDefaultSettings($h, $settings, $type = 'site') 
    508509        { 
    509                 if (!$settings) { return false; } else { $settings = serialize($settings); } 
    510                  
     510                if (!$settings) { 
     511                        return false; 
     512                } 
     513                $settings = serialize($settings); 
     514 
    511515                if ($type == 'site') { 
    512516                        // update the site defaults 
    513                         $sql = "UPDATE " . TABLE_MISCDATA . " SET miscdata_value = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
     517                        $sql = "UPDATE ".TABLE_MISCDATA." SET miscdata_value = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
    514518                        $h->db->query($h->db->prepare($sql, $settings, $h->currentUser->id, 'user_settings')); 
    515519                } elseif ($type == 'base') { 
    516520                        // update the base defaults 
    517                         $sql = "UPDATE " . TABLE_MISCDATA . " SET miscdata_default = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
     521                        $sql = "UPDATE ".TABLE_MISCDATA." SET miscdata_default = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
    518522                        $h->db->query($h->db->prepare($sql, $settings, $h->currentUser->id, 'user_settings')); 
    519523                } 
    520524        } 
    521  
    522525 
    523526        /** 
     
    527530         * @return array|false 
    528531         */ 
    529         public function getRoles($h, $type = 'all')  
    530         { 
    531                 switch ($type) 
    532                 { 
     532        public function getRoles($h, $type = 'all') 
     533        { 
     534                switch ($type) { 
    533535                        case 'default': 
    534536                                return $this->getDefaultRoles(); 
     
    543545        } 
    544546 
    545  
    546547        /** 
    547548         * Get Unique User Roles 
     
    549550         * @return array|false 
    550551         */ 
    551         public function getUniqueRoles($h)  
     552        public function getUniqueRoles($h) 
    552553        { 
    553554                $unique_roles = $this->getDefaultRoles(); 
    554                  
     555 
    555556                // Add any custom roles: 
    556557                $custom_roles = $this->getCustomRoles($h); 
    557                 if ($custom_roles) 
    558                 { 
    559                         foreach ($custom_roles as $role)  
    560                         { 
    561                                 if (!in_array($role, $unique_roles)) 
    562                                 {  
     558                if ($custom_roles) { 
     559                        foreach ($custom_roles as $role) { 
     560                                if (!in_array($role, $unique_roles)) { 
    563561                                        array_push($unique_roles, $role); 
    564562                                } 
    565563                        } 
    566564                } 
    567                  
    568                 if ($unique_roles) { return $unique_roles; } else { return false; } 
    569         } 
    570  
     565 
     566                if ($unique_roles) { 
     567                        return $unique_roles; 
     568                } 
     569                return false; 
     570        } 
    571571 
    572572        /** 
     
    575575         * @return array|false 
    576576         */ 
    577         public function getDefaultRoles()  
    578         { 
    579                 return array('admin', 'supermod', 'moderator', 'member', 'undermod', 'pending', 'suspended', 'banned', 'killspammed');  
    580         } 
    581  
     577        public function getDefaultRoles() 
     578        { 
     579                return array('admin', 'supermod', 'moderator', 'member', 'undermod', 'pending', 'suspended', 'banned', 'killspammed'); 
     580        } 
    582581 
    583582        /** 
     
    586585         * @return array|false 
    587586         */ 
    588         public function getCustomRoles($h)  
    589         { 
    590                 $sql = "SELECT miscdata_value FROM " . TABLE_MISCDATA . " WHERE miscdata_key = %s LIMIT 1"; 
     587        public function getCustomRoles($h) 
     588        { 
     589                $sql = "SELECT miscdata_value FROM ".TABLE_MISCDATA." WHERE miscdata_key = %s LIMIT 1"; 
    591590                $result = $h->db->get_var($h->db->prepare($sql, 'custom_roles')); 
    592                 if (!$result) { return false; }  
    593                  
     591                if (!$result) { 
     592                        return false; 
     593                } 
     594 
    594595                $custom_roles = unserialize($result); // result should be an array 
    595596 
    596                 return $custom_roles;  
    597         } 
    598  
     597                return $custom_roles; 
     598        } 
    599599 
    600600        /** 
     
    604604         * @return bool 
    605605         */ 
    606         public function addCustomRole($h, $new_role = '', $base_role = 'default')  
    607         { 
    608                 if (!$new_role) { return false; } 
     606        public function addCustomRole($h, $new_role = '', $base_role = 'default') 
     607        { 
     608                if (!$new_role) { 
     609                        return false; 
     610                } 
    609611 
    610612                $new_role = mb_strtolower($new_role, 'UTF-8'); 
     
    612614                // test if this role name is reserved: 
    613615                $default_roles = $this->getDefaultRoles(); 
    614                 if (in_array($new_role, $default_roles)) { return false; } 
     616                if (in_array($new_role, $default_roles)) { 
     617                        return false; 
     618                } 
    615619 
    616620                // test if this role name is already a custom role: 
    617621                $custom_roles = $this->getCustomRoles($h); 
    618                 if ($custom_roles && (in_array($new_role, $custom_roles))) { return false; } 
     622                if ($custom_roles && (in_array($new_role, $custom_roles))) { 
     623                        return false; 
     624                } 
    619625 
    620626                // add new role to custom roles 
    621                 if (!$custom_roles) { $custom_roles = array(); } 
     627                if (!$custom_roles) { 
     628                        $custom_roles = array(); 
     629                } 
    622630                array_push($custom_roles, $new_role); 
    623                  
     631 
    624632                // check custom_roles row exists in the database: 
    625                 $sql = "SELECT miscdata_id FROM " . TABLE_MISCDATA . " WHERE miscdata_key = %s LIMIT 1"; 
     633                $sql = "SELECT miscdata_id FROM ".TABLE_MISCDATA." WHERE miscdata_key = %s LIMIT 1"; 
    626634                $result = $h->db->get_var($h->db->prepare($sql, 'custom_roles')); 
    627635 
    628636                // update or insert accordingly  
    629                 if ($result) 
    630                 { 
    631                         $sql = "UPDATE " . TABLE_MISCDATA . " SET miscdata_value = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
     637                if ($result) { 
     638                        $sql = "UPDATE ".TABLE_MISCDATA." SET miscdata_value = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
    632639                        $h->db->query($h->db->prepare($sql, serialize($custom_roles), $h->currentUser->id, 'custom_roles')); 
    633                 }  
    634                 else  
    635                 { 
    636                         $sql = "INSERT INTO " . TABLE_MISCDATA . " (miscdata_key, miscdata_value, miscdata_updateby) VALUES(%s, %s, %d)"; 
     640                } else { 
     641                        $sql = "INSERT INTO ".TABLE_MISCDATA." (miscdata_key, miscdata_value, miscdata_updateby) VALUES(%s, %s, %d)"; 
    637642                        $h->db->query($h->db->prepare($sql, 'custom_roles', serialize($custom_roles), $h->currentUser->id)); 
    638643                } 
     
    651656        } 
    652657 
    653  
    654658        /** 
    655659         * Remove Custom User Role 
     
    659663         * @return bool 
    660664         */ 
    661         public function removeCustomRole($h, $remove_role = '', $move_to = '')  
    662         { 
    663                 if (!$remove_role) { return false; } 
     665        public function removeCustomRole($h, $remove_role = '', $move_to = '') 
     666        { 
     667                if (!$remove_role) { 
     668                        return false; 
     669                } 
    664670 
    665671                $remove_role = mb_strtolower($remove_role, 'UTF-8'); 
     
    667673                // return false if this is a default role: 
    668674                $default_roles = $this->getDefaultRoles(); 
    669                 if (in_array($remove_role, $default_roles)) { return false; } 
     675                if (in_array($remove_role, $default_roles)) { 
     676                        return false; 
     677                } 
    670678 
    671679                // return false if this is not a custom role: 
    672680                $custom_roles = $this->getCustomRoles($h); 
    673                 if (!$custom_roles || (!in_array($remove_role, $custom_roles))) { return false; } 
     681                if (!$custom_roles || (!in_array($remove_role, $custom_roles))) { 
     682                        return false; 
     683                } 
    674684 
    675685                // update all users with the old role 
    676                 if ($move_to) { $this->bulkRoleChange($h, $remove_role, $move_to); } 
     686                if ($move_to) { 
     687                        $this->bulkRoleChange($h, $remove_role, $move_to); 
     688                } 
    677689 
    678690                // remove role from custom roles 
    679691                $custom_roles = array_remove($custom_roles, $remove_role); // custom Hotaru function 
    680  
    681692                // update custom_roles record 
    682                 $sql = "UPDATE " . TABLE_MISCDATA . " SET miscdata_value = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
     693                $sql = "UPDATE ".TABLE_MISCDATA." SET miscdata_value = %s, miscdata_updateby = %d WHERE miscdata_key = %s"; 
    683694                $h->db->query($h->db->prepare($sql, serialize($custom_roles), $h->currentUser->id, 'custom_roles')); 
    684695 
     
    696707        } 
    697708 
    698  
    699709        /** 
    700710         * Bulk User Role Change 
     
    704714         * @return bool 
    705715         */ 
    706         public function bulkRoleChange($h, $from = '', $to = '')  
    707         { 
    708                 if (!$from || !$to) { return false; } 
     716        public function bulkRoleChange($h, $from = '', $to = '') 
     717        { 
     718                if (!$from || !$to) { 
     719                        return false; 
     720                } 
    709721 
    710722                // check $from and $to exist 
    711723                $unique_roles = $this->getUniqueRoles($h); 
    712                 if (!in_array($from, $unique_roles)) { return false; } 
    713                 if (!in_array($to, $unique_roles)) { return false; } 
    714  
    715                 $sql = "SELECT user_id FROM " . TABLE_USERS . " WHERE user_role = %s"; 
     724                if (!in_array($from, $unique_roles)) { 
     725                        return false; 
     726                } 
     727                if (!in_array($to, $unique_roles)) { 
     728                        return false; 
     729                } 
     730 
     731                $sql = "SELECT user_id FROM ".TABLE_USERS." WHERE user_role = %s"; 
    716732                $items = $h->db->get_results($h->db->prepare($sql, $from)); 
    717                 if ($items)  
    718                 { 
     733                if ($items) { 
    719734                        // Change role and permissions for each user being moved 
    720                         foreach ($items as $item)  
    721                         { 
     735                        foreach ($items as $item) { 
    722736                                $user = new UserAuth(); 
    723737                                $user->getUser($h, $item->user_id); 
     
    728742                        } 
    729743                } 
    730                  
     744 
    731745                return true; 
    732746        } 
    733  
    734747 
    735748        /** 
     
    741754         * @return array 
    742755         */ 
    743         public function copyRolePerms($h, $perms = array(), $new_role = '', $base_role = 'default')  
    744         { 
    745                 if (!$perms || !$new_role) { return array(); } 
     756        public function copyRolePerms($h, $perms = array(), $new_role = '', $base_role = 'default') 
     757        { 
     758                if (!$perms || !$new_role) { 
     759                        return array(); 
     760                } 
    746761 
    747762                $new_perms = array(); 
    748763 
    749                 foreach ($perms as $perm => $roles) 
    750                 { 
    751                         foreach ($roles as $role => $value) 
    752                         { 
    753                                 if ($role == $base_role) 
    754                                 { 
     764                foreach ($perms as $perm => $roles) { 
     765                        foreach ($roles as $role => $value) { 
     766                                if ($role == $base_role) { 
    755767                                        $new_perms[$perm][$new_role] = $value; 
    756768                                } 
    757                         }  
     769                        } 
    758770                } 
    759771 
    760772                return $new_perms; 
    761773        } 
    762  
    763774 
    764775        /** 
     
    770781         * @return array 
    771782         */ 
    772         public function removeRolePerms($h, $perms = array(), $delete_role = '')  
    773         { 
    774                 if (!$perms || !$delete_role) { return array(); } 
    775  
    776                 foreach ($perms as $perm => $roles) 
    777                 { 
    778                         foreach ($roles as $role => $value) 
    779                         { 
    780                                 if ($role == $delete_role) 
    781                                 { 
     783        public function removeRolePerms($h, $perms = array(), $delete_role = '') 
     784        { 
     785                if (!$perms || !$delete_role) { 
     786                        return array(); 
     787                } 
     788 
     789                foreach ($perms as $perm => $roles) { 
     790                        foreach ($roles as $role => $value) { 
     791                                if ($role == $delete_role) { 
    782792                                        unset($perms[$perm][$delete_role]); 
    783793                                } 
    784                         }  
     794                        } 
    785795                } 
    786796 
    787797                return $perms; 
    788798        } 
     799 
    789800} 
  • branches/1.5/libs/UserInfo.php

    r2168 r2292  
    2626class UserInfo extends UserBase 
    2727{ 
     28 
    2829        /** 
    2930         * Get the username for a given user id 
     
    3435        public function getUserNameFromId($h, $id = 0) 
    3536        { 
    36                 $sql = "SELECT user_username FROM " . TABLE_USERS . " WHERE user_id = %d LIMIT 1"; 
    37                  
     37                $sql = "SELECT user_username FROM ".TABLE_USERS." WHERE user_id = %d LIMIT 1"; 
     38 
    3839                $username = $h->db->get_var($h->db->prepare($sql, $id)); 
    39                 if ($username) { return $username; } else { return false; } 
    40         } 
    41          
    42          
     40                if ($username) { 
     41                        return $username; 
     42                } 
     43                return false; 
     44        } 
     45 
    4346        /** 
    4447         * Get the user id for a given username 
     
    4952        public function getUserIdFromName($h, $username = '') 
    5053        { 
    51                 $sql = "SELECT user_id FROM " . TABLE_USERS . " WHERE user_username = %s  LIMIT 1"; 
    52                  
     54                $sql = "SELECT user_id FROM ".TABLE_USERS." WHERE user_username = %s  LIMIT 1"; 
     55 
    5356                $userid = $h->db->get_var($h->db->prepare($sql, $username)); 
    54                 if ($userid) { return $userid; } else { return false; } 
    55         } 
    56          
    57          
     57                if ($userid) { 
     58                        return $userid; 
     59                } 
     60                return false; 
     61        } 
     62 
    5863        /** 
    5964         * Get the email from user id 
     
    6469        public function getEmailFromId($h, $userid = 0) 
    6570        { 
    66                 $sql = "SELECT user_email FROM " . TABLE_USERS . " WHERE user_id = %d  LIMIT 1"; 
    67                  
     71                $sql = "SELECT user_email FROM ".TABLE_USERS." WHERE user_id = %d  LIMIT 1"; 
     72 
    6873                $email = $h->db->get_var($h->db->prepare($sql, $userid)); 
    69                 if ($email) { return $email; } else { return false; } 
    70         } 
    71          
    72          
     74                if ($email) { 
     75                        return $email; 
     76                } 
     77                return false; 
     78        } 
     79 
    7380        /** 
    7481         * Get the user id from email 
     
    7986        public function getUserIdFromEmail($h, $email = '') 
    8087        { 
    81                 $sql = "SELECT user_id FROM " . TABLE_USERS . " WHERE user_email = %s  LIMIT 1"; 
    82                  
     88                $sql = "SELECT user_id FROM ".TABLE_USERS." WHERE user_email = %s  LIMIT 1"; 
     89 
    8390                $userid = $h->db->get_var($h->db->prepare($sql, $email)); 
    84                 if ($userid) { return $userid; } else { return false; } 
    85         } 
    86          
    87          
    88          /** 
     91                if ($userid) { 
     92                        return $userid; 
     93                } 
     94                return false; 
     95        } 
     96 
     97        /** 
    8998         * Checks if the user has an 'admin' role 
    9099         * 
     
    93102        public function isAdmin($db, $username) 
    94103        { 
    95                 $sql = "SELECT * FROM " . TABLE_USERS . " WHERE user_username = %s AND user_role = %s  LIMIT 1"; 
    96                 $role = $db->get_row($db->prepare($sql, $username, 'admin')); 
    97                  
    98                 if ($role) { return true; } else { return false; } 
    99         } 
    100          
    101          
     104                $sql = "SELECT * FROM ".TABLE_USERS." WHERE user_username = %s AND user_role = %s  LIMIT 1"; 
     105                return (bool) $db->get_row($db->prepare($sql, $username, 'admin')); 
     106        } 
     107 
    102108        /** 
    103109         * Check if a user exists 
     
    113119                // id found 
    114120                if ($id != 0) { 
    115                         if ($db->get_var($db->prepare("SELECT user_id FROM " . TABLE_USERS . " WHERE user_id = %d  LIMIT 1", $id))) { 
     121                        if ($db->get_var($db->prepare("SELECT user_id FROM ".TABLE_USERS." WHERE user_id = %d  LIMIT 1", $id))) { 
    116122                                return 'id'; // id exists 
    117                         }  
    118                 }  
    119                  
     123                        } 
     124                } 
     125 
    120126                // name found 
    121127                if ($username != '') { 
    122                         if ($db->get_var($db->prepare("SELECT user_id FROM " . TABLE_USERS . " WHERE user_username = %s  LIMIT 1", $username))) { 
     128                        if ($db->get_var($db->prepare("SELECT user_id FROM ".TABLE_USERS." WHERE user_username = %s  LIMIT 1", $username))) { 
    123129                                return 'name'; // username exists 
    124130                        } 
    125                 }  
    126                  
     131                } 
     132 
    127133                // email found 
    128134                if ($email != '') { 
    129                         if ($db->get_var($db->prepare("SELECT user_id FROM " . TABLE_USERS . " WHERE user_email = %s  LIMIT 1", $email))) { 
     135                        if ($db->get_var($db->prepare("SELECT user_id FROM ".TABLE_USERS." WHERE user_email = %s  LIMIT 1", $email))) { 
    130136                                return 'email'; // email exists 
    131137                        } 
    132                 }  
    133                  
     138                } 
     139 
    134140                // Error - no arguments provided 
    135141                if (($id == 0) && ($username == '') && ($email == '')) { 
    136142                        return 'error'; // no arguments provided 
    137                 }  
    138                  
     143                } 
     144 
    139145                return 'no'; // User doesn't exist 
    140146        } 
    141          
    142          
     147 
    143148        /** 
    144149         * Check if an username exists in the database (used in forgotten password) 
     
    151156        public function nameExists($h, $username = '', $role = '', $exclude = 0) 
    152157        { 
    153                 if (!$username) {  return false; } 
    154                  
    155                 if (!$exclude) { 
    156                         if ($role) {  
    157                                 $sql = "SELECT user_username FROM " . TABLE_USERS . " WHERE user_username = %s AND user_role = %s  LIMIT 1"; 
    158                                 $valid_username = $h->db->get_var($h->db->prepare($sql, $username, $role)); 
    159                         } else { 
    160                                 $sql = "SELECT user_username FROM " . TABLE_USERS . " WHERE user_username = %s  LIMIT 1"; 
    161                                 $valid_username = $h->db->get_var($h->db->prepare($sql, $username)); 
    162                         } 
    163                 } else { 
    164                         if ($role) {  
    165                                 $sql = "SELECT user_username FROM " . TABLE_USERS . " WHERE user_username = %s AND user_role = %s AND user_id != %d  LIMIT 1"; 
    166                                 $valid_username = $h->db->get_var($h->db->prepare($sql, $username, $role, $exclude)); 
    167                         } else { 
    168                                 $sql = "SELECT user_username FROM " . TABLE_USERS . " WHERE user_username = %s AND user_id != %d  LIMIT 1"; 
    169                                 $valid_username = $h->db->get_var($h->db->prepare($sql, $username, $exclude)); 
    170                         } 
    171                 } 
    172          
    173                 if ($valid_username) { return $valid_username; } else { return false; } 
    174         } 
    175          
    176          
     158                if (!$username) { 
     159                        return false; 
     160                } 
     161 
     162                $q_role = ($role) ? 'AND user_role = %s' : ''; 
     163                $q_exclude = (!$exclude) ? ' AND user_id != %d' : ''; 
     164                $sql = "SELECT user_username FROM ".TABLE_USERS." WHERE user_username = %s".$q_role.$q_exclude." LIMIT 1"; 
     165                $valid_username = $h->db->get_var($h->db->prepare($sql, $username, $role, $exclude)); 
     166                if ($valid_username) { 
     167                        return $valid_username; 
     168                } 
     169 
     170                return FALSE; 
     171        } 
     172 
    177173        /** 
    178174         * Check if an email exists in the database (used in forgotten password) 
     
    185181        public function emailExists($h, $email = '', $role = '', $exclude = 0) 
    186182        { 
    187                 if (!$email) {  return false; } 
    188                  
    189                 if (!$exclude) { 
    190                         if ($role) {  
    191                                 $sql = "SELECT user_email FROM " . TABLE_USERS . " WHERE user_email = %s AND user_role = %s  LIMIT 1"; 
    192                                 $valid_email = $h->db->get_var($h->db->prepare($sql, $email, $role)); 
    193                         } else { 
    194                                 $sql = "SELECT user_email FROM " . TABLE_USERS . " WHERE user_email = %s  LIMIT 1"; 
    195                                 $valid_email = $h->db->get_var($h->db->prepare($sql, $email)); 
    196                         } 
    197                 } else { 
    198                         if ($role) {  
    199                                 $sql = "SELECT user_email FROM " . TABLE_USERS . " WHERE user_email = %s AND user_role = %s AND user_id != %d  LIMIT 1"; 
    200                                 $valid_email = $h->db->get_var($h->db->prepare($sql, $email, $role, $exclude)); 
    201                         } else { 
    202                                 $sql = "SELECT user_email FROM " . TABLE_USERS . " WHERE user_email = %s AND user_id != %d  LIMIT 1"; 
    203                                 $valid_email = $h->db->get_var($h->db->prepare($sql, $email, $exclude)); 
    204                         } 
    205                 } 
    206                  
    207                 if ($valid_email) { return $valid_email; } else { return false; } 
    208         } 
    209          
    210          
     183                if (!$email) { 
     184                        return false; 
     185                } 
     186 
     187                $q_role = ($role) ? 'AND user_role = %s' : ''; 
     188                $q_exclude = (!$exclude) ? ' AND user_id != %d' : ''; 
     189                $sql = "SELECT user_email FROM ".TABLE_USERS." WHERE user_username = %s".$q_role.$q_exclude." LIMIT 1"; 
     190                $valid_email = $h->db->get_var($h->db->prepare($sql, $email, $role, $exclude)); 
     191                if ($valid_email) { 
     192                        return $valid_email; 
     193                } 
     194 
     195                return FALSE; 
     196        } 
     197 
    211198        /** 
    212199         * Get all users with permission to access admin 
     
    214201        public function getMods($h, $permission = 'can_access_admin', $value = 'yes') 
    215202        { 
    216                 $sql = "SELECT user_id FROM " . TABLE_USERS . " WHERE (user_role = %s) || (user_role = %s) || (user_role = %s)"; 
     203                $sql = "SELECT user_id FROM ".TABLE_USERS." WHERE (user_role = %s) || (user_role = %s) || (user_role = %s)"; 
    217204                $users = $h->db->get_results($h->db->prepare($sql, 'admin', 'supermod', 'moderator')); 
    218          
    219                 if (!$users) { return false; } 
    220                  
     205 
     206                if (!$users) { 
     207                        return false; 
     208                } 
     209 
    221210                $mods = array(); 
    222                  
     211 
    223212                foreach ($users as $user) { 
    224213                        $details = new UserBase(); 
     
    233222                return $mods; 
    234223        } 
    235          
    236          
     224 
    237225        /** 
    238226         * Get the ids and names of all users or those with a specified role, sorted alphabetically 
     
    243231        public function userIdNameList($h, $role = '') 
    244232        { 
    245                 if ($role) {  
    246                         $sql = "SELECT user_id, user_username FROM " . TABLE_USERS . " WHERE user_role = %s ORDER BY user_username ASC"; 
     233                if ($role) { 
     234                        $sql = "SELECT user_id, user_username FROM ".TABLE_USERS." WHERE user_role = %s ORDER BY user_username ASC"; 
    247235                        $results = $h->db->get_results($h->db->prepare($sql, $role)); 
    248236                } else { 
    249                         $sql = "SELECT user_id, user_username FROM " . TABLE_USERS . " ORDER BY user_username ASC"; 
     237                        $sql = "SELECT user_id, user_username FROM ".TABLE_USERS." ORDER BY user_username ASC"; 
    250238                        $results = $h->db->get_results($sql); 
    251239                } 
    252                  
     240 
    253241                return $results; 
    254242        } 
    255          
    256          
     243 
    257244        /** 
    258245         * Get settings for all users 
     
    262249        public function userSettingsList($h, $userid = 0) 
    263250        { 
    264                 if ($userid) {  
     251                if ($userid) { 
    265252                        $settings = $h->getProfileSettingsData($type = 'user_settings', $userid); 
    266253                        return $settings; 
    267254                } else { 
    268                         $sql = "SELECT usermeta_userid, usermeta_value FROM " . DB_PREFIX . "usermeta WHERE usermeta_key = %s"; 
     255                        $sql = "SELECT usermeta_userid, usermeta_value FROM ".TABLE_USERMETA." WHERE usermeta_key = %s"; 
    269256                        $results = $h->db->get_results($h->db->prepare($sql, 'user_settings')); 
    270257                } 
    271                  
     258 
    272259                return $results; 
    273260        } 
    274          
    275          
     261 
    276262        /** 
    277263         * Get full details of all users or batches of users, sorted alphabetically 
     
    286272                if (!$id_array) { 
    287273                        // get all users 
    288                         $sql = "SELECT * FROM " . TABLE_USERS . " ORDER BY user_username ASC"; 
     274                        $sql = "SELECT * FROM ".TABLE_USERS." ORDER BY user_username ASC"; 
    289275                        $results = $h->db->get_results($sql); 
    290276                } else { 
    291277                        // for grabbing  
    292                         if ($range) { $limit = " LIMIT " . $start . ", " . $range; } 
    293                         $sql = "SELECT * FROM " . TABLE_USERS . " WHERE "; 
    294                         for ($i=0; $i < count($id_array); $i++) { 
     278                        if ($range) { 
     279                                $limit = " LIMIT ".$start.", ".$range; 
     280                        } 
     281                        $sql = "SELECT * FROM ".TABLE_USERS." WHERE "; 
     282                        for ($i = 0; $i < count($id_array); $i++) { 
    295283                                $sql .= "user_id = %d OR "; 
    296284                        } 
    297285                        $sql = rstrtrim($sql, "OR "); // strip trailing OR 
    298                         $sql .= " ORDER BY user_username ASC" . $limit; 
    299                  
     286                        $sql .= " ORDER BY user_username ASC".$limit; 
     287 
    300288                        $prepare_array[0] = $sql; 
    301289                        $prepare_array = array_merge($prepare_array, $id_array); 
     
    304292                return $results; 
    305293        } 
    306          
    307          
     294 
    308295        /** 
    309296         * Stats for Admin homepage 
     
    314301        public function stats($h) 
    315302        { 
    316                 $sql = "SELECT user_role, count(user_id) FROM " . TABLE_USERS . " GROUP BY user_role"; 
     303                $sql = "SELECT user_role, count(user_id) FROM ".TABLE_USERS." GROUP BY user_role"; 
    317304                $query = $h->db->prepare($sql); 
    318305                $h->smartCache('on', 'users', 60, $query); // start using cache 
    319306                $users = $h->db->get_results($query, 'ARRAY_N'); 
    320307                $h->smartCache('off'); // stop using cache 
    321                  
     308 
    322309                return $users; 
    323310        } 
     311 
    324312} 
  • branches/1.5/libs/Widget.php

    r2185 r2292  
    2424 * @link      http://www.hotarucms.org/ 
    2525 */ 
    26  
    2726class Widget 
    2827{ 
     28 
    2929        /** 
    3030         * Initialize widgets 
     
    3333        { 
    3434                // Get settings from the database if they exist... 
    35                 $widgets_settings = $h->getSerializedSettings('widgets');  
    36                  
     35                $widgets_settings = $h->getSerializedSettings('widgets'); 
     36 
    3737                if ($widgets_settings) { 
    3838                        // delete completely any widgets from uninstalled plugins: 
     
    4747                        } 
    4848                } 
    49                  
     49 
    5050                $widgets = $this->getWidgets($h); 
    51                  
     51 
    5252                if ($widgets) { 
    5353                        $count = 1; 
    5454                        foreach ($widgets as $widget) { 
    55                          
     55 
    5656                                // Assign order number if not already assigned one. 
    5757                                if (!isset($widgets_settings['widgets'][$widget->widget_function]['order'])) { 
    5858                                        $widgets_settings['widgets'][$widget->widget_function]['order'] = $count; 
    5959                                } 
    60                                  
     60 
    6161                                // Assign widget number if not already assigned one. 
    6262                                if (!isset($widgets_settings['widgets'][$widget->widget_function]['block'])) { 
    6363                                        $widgets_settings['widgets'][$widget->widget_function]['block'] = 1; 
    6464                                } 
    65                                  
     65 
    6666                                // Enable the widget if enabled status is not currently set... 
    6767                                if (!isset($widgets_settings['widgets'][$widget->widget_function]['enabled'])) { 
    6868                                        $widgets_settings['widgets'][$widget->widget_function]['enabled'] = true; 
    6969                                } 
    70                                  
     70 
    7171                                // But! Disable it if the plugin for that widget is not currently active. 
    72                                 if (!$h->isActive($widget->widget_plugin) ) { 
     72                                if (!$h->isActive($widget->widget_plugin)) { 
    7373                                        $widgets_settings['widgets'][$widget->widget_function]['enabled'] = false; 
    7474                                } 
    75                                  
     75 
    7676                                // Add plugin name, function suffix and arguments to widget_settings: 
    7777                                $widgets_settings['widgets'][$widget->widget_function]['plugin'] = $widget->widget_plugin; 
     
    7979                                $widgets_settings['widgets'][$widget->widget_function]['function'] = $widget->widget_function; 
    8080                                $widgets_settings['widgets'][$widget->widget_function]['args'] = $widget->widget_args; 
    81                                  
     81 
    8282                                $count++; 
    8383                        } 
    8484                } 
    85                  
     85 
    8686                $h->updateSetting('widgets_settings', serialize($widgets_settings), 'widgets'); 
    8787        } 
    88          
    89          
     88 
    9089        /** 
    9190         * Add widget 
     
    10099                $sql = "SELECT count(widget_id) FROM " . DB_PREFIX . "widgets WHERE widget_plugin = %s AND widget_function = %s AND widget_args = %s"; 
    101100                $result = $h->db->get_var($h->db->prepare($sql, $plugin, $function, $args)); 
    102                  
     101 
    103102                if (!$result) { 
    104103                        $sql = "INSERT INTO " . DB_PREFIX . "widgets (widget_plugin, widget_function, widget_args, widget_updateby) VALUES(%s, %s, %s, %d)"; 
     
    108107                $h->db->query("OPTIMIZE TABLE " . DB_PREFIX . "widgets"); 
    109108        } 
    110          
    111          
     109 
    112110        /** 
    113111         * Get widgets from widget db table 
     
    118116        { 
    119117                $exists = $h->db->table_exists('widgets'); 
    120                  
    121                 if (!$exists) { return false; } 
    122                  
    123                 // Get settings from the database if they exist... 
    124                 $sql = "SELECT widget_plugin, widget_function, widget_args FROM " . DB_PREFIX . 'widgets'; 
     118 
     119                if (!$exists) { 
     120                        return false; 
     121                } 
     122 
     123                // Get settings from the database if they exist... 
     124                $sql = "SELECT widget_plugin, widget_function, widget_args FROM ".DB_PREFIX.'widgets'; 
    125125                $widgets_settings = $h->db->get_results($h->db->prepare($sql)); 
    126126                return $widgets_settings; 
    127127        } 
    128          
    129          
     128 
    130129        /** 
    131130         * Get widgets from widgets_settings array 
     
    140139        { 
    141140                // Get settings from the database if they exist... 
    142                 $widgets_settings = $h->getSerializedSettings('widgets');  
    143                  
    144                 if (!$widgets_settings['widgets']) { return false; } 
    145  
    146                 $widgets = $widgets_settings['widgets'];    // associative array 
    147                  
     141                $widgets_settings = $h->getSerializedSettings('widgets'); 
     142 
     143                if (!$widgets_settings['widgets']) { 
     144                        return false; 
     145                } 
     146 
     147                $widgets = $widgets_settings['widgets'];        // associative array 
    148148                // return an individual widget 
    149                 if ($widget_name && isset($widgets[$widget_name])) {  
    150                         if (!$h->isActive($widgets[$widget_name]['plugin'])) {  
    151                                 return false;  
    152                         } else {  
    153                                 return $widgets[$widget_name];  
    154                         } 
    155                 } 
    156          
    157                 $widgets = $this->orderWidgets($widgets);    // sorts plugins by "order" 
    158          
     149                if ($widget_name && isset($widgets[$widget_name])) { 
     150                        if (!$h->isActive($widgets[$widget_name]['plugin'])) { 
     151                                return false; 
     152                        } else { 
     153                                return $widgets[$widget_name]; 
     154                        } 
     155                } 
     156 
     157                $widgets = $this->orderWidgets($widgets);       // sorts plugins by "order" 
     158 
    159159                return $widgets; 
    160160        } 
    161          
    162          
     161 
    163162        /** 
    164163         * Delete a widget from the widget db table 
     
    172171                        // Cached results tell us the widget's plugin is uninstalled, but if we  
    173172                        // know the plugin, let's double check before deleting it: 
    174                         $sql = "SELECT plugin_id FROM " . TABLE_PLUGINS . " WHERE plugin_folder = %s"; 
     173                        $sql = "SELECT plugin_id FROM ".TABLE_PLUGINS." WHERE plugin_folder = %s"; 
    175174                        $result = $h->db->get_var($h->db->prepare($sql, $plugin)); 
    176                         if ($result) { return false; } //plugin still installed, don't delete 
    177                 } 
    178                  
    179                 // Get settings from the database if they exist... 
    180                 $sql = "DELETE FROM " . DB_PREFIX . "widgets WHERE widget_function = %s"; 
     175                        if ($result) { 
     176                                return false; 
     177                        } //plugin still installed, don't delete 
     178                } 
     179 
     180                // Get settings from the database if they exist... 
     181                $sql = "DELETE FROM ".DB_PREFIX."widgets WHERE widget_function = %s"; 
    181182                $h->db->query($h->db->prepare($sql, $function)); 
    182                  
    183                 $h->db->query("OPTIMIZE TABLE " . TABLE_WIDGETS); 
    184         } 
    185          
     183 
     184                $h->db->query("OPTIMIZE TABLE ".DB_PREFIX."widgets"); 
     185        } 
     186 
    186187        /** 
    187188         * Sort the widgets by order number 
     
    192193        public function orderWidgets($widgets = array()) 
    193194        { 
    194                 if (!$widgets) { return false; } 
     195                if (!$widgets) { 
     196                        return false; 
     197                } 
    195198                return sksort($widgets, "order", "int", true); 
    196199        } 
    197          
    198          
     200 
    199201        /** 
    200202         * Get last block 
     
    205207        public function getLastWidgetBlock($widgets) 
    206208        { 
    207                 if (!$widgets) { return 1; } 
    208                  
     209                if (!$widgets) { 
     210                        return 1; 
     211                } 
     212 
    209213                $highest = 1; 
    210214                foreach ($widgets as $widget => $details) { 
    211                         if (isset($details['block']) && ($details['block'] > $highest)) { $highest = $details['block']; } 
     215                        if (isset($details['block']) && ($details['block'] > $highest)) { 
     216                                $highest = $details['block']; 
     217                        } 
    212218                } 
    213219                return $highest; 
    214220        } 
    215          
    216          
     221 
    217222        /** 
    218223         * Get plugin name from widget function name 
     
    223228        { 
    224229                // Get settings from the database if they exist... 
    225                 $sql = "SELECT widget_plugin FROM " . TABLE_WIDGETS . ' WHERE widget_function = %s LIMIT 1'; 
     230                $sql = "SELECT widget_plugin FROM ".DB_PREFIX."widgets WHERE widget_function = %s LIMIT 1"; 
    226231                $widget_plugin = $h->db->get_var($h->db->prepare($sql, $function)); 
    227232                return $widget_plugin; 
     
    229234 
    230235} 
    231  
    232 ?>