diff --git a/root/includes/acp/acp_portal.php b/root/includes/acp/acp_portal.php index 9f67ef32..4858cee9 100644 --- a/root/includes/acp/acp_portal.php +++ b/root/includes/acp/acp_portal.php @@ -230,6 +230,7 @@ class acp_portal WHERE module_id = ' . $module_id; $db->sql_query($sql); + $cache->destroy('portal_modules'); $cache->destroy('sql', CONFIG_TABLE); if(isset($module_name)) { @@ -345,6 +346,8 @@ class acp_portal $db->sql_query($sql); } } + + $cache->destroy('portal_modules'); } elseif ($action == 'move_down') { @@ -371,6 +374,8 @@ class acp_portal $db->sql_query($sql); } } + + $cache->destroy('portal_modules'); } elseif($action == 'move_right') { @@ -473,6 +478,8 @@ class acp_portal { trigger_error($user->lang['UNABLE_TO_MOVE'] . adm_back_link($this->u_action)); } + + $cache->destroy('portal_modules'); } elseif($action == 'move_left') { @@ -574,6 +581,8 @@ class acp_portal { trigger_error($user->lang['UNABLE_TO_MOVE'] . adm_back_link($this->u_action)); } + + $cache->destroy('portal_modules'); } elseif ($action == 'delete') { @@ -634,6 +643,8 @@ class acp_portal ))); } } + + $cache->destroy('portal_modules'); } $add_module = key(request_var('add', array('' => ''))); @@ -755,12 +766,9 @@ class acp_portal { $directory = $phpbb_root_path . 'portal/modules/'; - $sql = 'SELECT * - FROM ' . PORTAL_MODULES_TABLE . ' - ORDER BY module_column, module_order ASC'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) + $portal_modules = obtain_portal_modules(); + + foreach($portal_modules as $row) { $class = 'portal_' . $row['module_classname'] . '_module'; if (!class_exists($class)) @@ -810,7 +818,6 @@ class acp_portal 'U_MOVE_LEFT' => ($move_left) ? $this->u_action . '&module_id=' . $row['module_id'] . '&action=move_left' : '', )); } - $db->sql_freeresult($result); $template->assign_vars(array( 'ICON_MOVE_LEFT' => '' . $user->lang['MOVE_LEFT'] . '', diff --git a/root/portal.php b/root/portal.php index eca5add8..edf28cf6 100644 --- a/root/portal.php +++ b/root/portal.php @@ -52,7 +52,94 @@ $module_count = array( 'bottom' => 0, ); +$portal_modules = obtain_portal_modules(); +foreach($portal_modules as $row) +{ + $class_name = 'portal_' . $row['module_classname'] . '_module'; + if (!class_exists($class_name)) + { + include("{$phpbb_root_path}{$portal_root_path}modules/portal_{$row['module_classname']}.$phpEx"); + } + if (!class_exists($class_name)) + { + trigger_error(sprintf($user->lang['CLASS_NOT_FOUND'], $class_name, 'portal_' . $row['module_classname']), E_USER_ERROR); + } + + + $module = new $class_name(); + + // Check for permissions before loading anything + $group_ary = (!empty($row['module_group_ids'])) ? explode(',', $row['module_group_ids']) : ''; + if((is_array($group_ary) && !in_array($user->data['group_id'], $group_ary))) + { + continue; + } + + if ($module->language) + { + $user->add_lang('mods/portal/' . $module->language); + } + if ($row['module_column'] == 1 && $config['board3_left_column']) + { + $template_module = $module->get_template_side($row['module_id']); + $template_column = 'left'; + ++$module_count['left']; + } + if ($row['module_column'] == 2) + { + $template_module = $module->get_template_center($row['module_id']); + $template_column = 'center'; + ++$module_count['center']; + } + if ($row['module_column'] == 3 && $config['board3_right_column']) + { + $template_module = $module->get_template_side($row['module_id']); + $template_column = 'right'; + ++$module_count['right']; + } + if ($row['module_column'] == 4) + { + $template_module = $module->get_template_center($row['module_id']); + ++$module_count['top']; + } + if ($row['module_column'] == 5) + { + $template_module = $module->get_template_center($row['module_id']); + ++$module_count['bottom']; + } + if (!isset($template_module)) + { + continue; + } + + // Custom Blocks that have been defined in the ACP will return an array instead of just the name of the template file + if(is_array($template_module)) + { + $template->assign_block_vars('modules_' . column_num_string($row['module_column']), array( + 'TEMPLATE_FILE' => 'portal/modules/' . $template_module['template'], + 'IMAGE_SRC' => $phpbb_root_path . 'styles/' . $user->theme['theme_path'] . '/theme/images/portal/' . $template_module['image_src'], + 'TITLE' => $template_module['title'], + 'CODE' => $template_module['code'], + 'MODULE_ID' => $row['module_id'], + )); + } + else + { + $template->assign_block_vars('modules_' . column_num_string($row['module_column']), array( + 'TEMPLATE_FILE' => 'portal/modules/' . $template_module, + 'IMAGE_SRC' => $phpbb_root_path . 'styles/' . $user->theme['theme_path'] . '/theme/images/portal/' . $row['module_image_src'], + 'IMAGE_WIDTH' => $row['module_image_width'], + 'IMAGE_HEIGHT' => $row['module_image_height'], + 'MODULE_ID' => $row['module_id'], + 'TITLE' => (isset($user->lang[$row['module_name']])) ? $user->lang[$row['module_name']] : utf8_normalize_nfc($row['module_name']), + )); + } + unset($template_module); +} +$module_count['total'] = sizeof($portal_modules); + +/* $sql = 'SELECT * FROM ' . PORTAL_MODULES_TABLE . ' ORDER BY module_order ASC'; @@ -142,6 +229,7 @@ while ($row = $db->sql_fetchrow($result)) } $module_count['total'] = $db->sql_affectedrows(); $db->sql_freeresult($result); +*/ // Redirect to index if there are currently no active modules if($module_count['total'] < 1) @@ -154,9 +242,9 @@ $template->assign_vars(array( 'S_SMALL_BLOCK' => true, 'S_PORTAL_LEFT_COLUMN' => $config['board3_left_column_width'], 'S_PORTAL_RIGHT_COLUMN' => $config['board3_right_column_width'], - 'S_LEFT_COLUMN' => ($module_count['left'] > 0) ? true : false, + 'S_LEFT_COLUMN' => ($module_count['left'] > 0 && $config['board3_left_column']) ? true : false, 'S_CENTER_COLUMN' => ($module_count['center'] > 0) ? true : false, - 'S_RIGHT_COLUMN' => ($module_count['right'] > 0) ? true : false, + 'S_RIGHT_COLUMN' => ($module_count['right'] > 0 && $config['board3_right_column']) ? true : false, 'S_TOP_COLUMN' => ($module_count['top'] > 0) ? true : false, 'S_BOTTOM_COLUMN' => ($module_count['bottom'] > 0) ? true : false, 'S_DISPLAY_PHPBB_MENU' => $config['board3_phpbb_menu'], diff --git a/root/portal/includes/functions.php b/root/portal/includes/functions.php index 2a32c637..0f7e252e 100644 --- a/root/portal/includes/functions.php +++ b/root/portal/includes/functions.php @@ -17,19 +17,25 @@ if (!defined('IN_PHPBB') && !defined('UMIL_AUTO') && !defined('IN_INSTALL')) // Get portal config function obtain_portal_config() { - global $db, $portal_config; + global $db, $cache, $portal_config; - if(sizeof($portal_config) < 1) + if (($portal_config = $cache->get('portal_config')) === false) { + $portal_config = $portal_cached_config = array(); + $sql = 'SELECT config_name, config_value FROM ' . PORTAL_CONFIG_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { + $portal_cached_config[$row['config_name']] = $row['config_value']; + $portal_config[$row['config_name']] = $row['config_value']; } $db->sql_freeresult($result); + + $cache->put('portal_config', $portal_cached_config); } return $portal_config; @@ -57,6 +63,38 @@ function set_portal_config($config_name, $config_value) } $portal_config[$config_name] = $config_value; + + $cache->destroy('portal_config'); +} + +/** +* Get portal modules +*/ +function obtain_portal_modules() +{ + global $db, $cache, $portal_modules; + + if (($portal_modules = $cache->get('portal_modules')) === false) + { + $portal_modules = $portal_cached_modules = array(); + + $sql = 'SELECT * + FROM ' . PORTAL_MODULES_TABLE . ' + ORDER BY module_order ASC'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $portal_cached_modules[] = $row; + + $portal_modules[] = $row; + } + $db->sql_freeresult($result); + + $cache->put('portal_modules', $portal_cached_modules); + } + + return $portal_modules; } // fetch post for news & announce