Merge pull request #131 from marc1706/feature/acp

[feature/acp] Convert ACP module to new extension system
This commit is contained in:
Marc Alexander
2013-03-22 05:49:13 -07:00
4 changed files with 41 additions and 36 deletions

View File

@@ -15,12 +15,12 @@ if (!defined('IN_PHPBB'))
/** /**
* @package module_install * @package module_install
*/ */
class acp_portal_info class phpbb_ext_board3_portal_acp_portal_info
{ {
public function module() public function module()
{ {
return array( return array(
'filename' => 'acp_portal', 'filename' => 'phpbb_ext_board3_portal_acp_portal_module',
'title' => 'ACP_PORTAL', 'title' => 'ACP_PORTAL',
'version' => '2.0.0b2', 'version' => '2.0.0b2',
'modes' => array( 'modes' => array(

View File

@@ -15,21 +15,24 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
class acp_portal class phpbb_ext_board3_portal_acp_portal_module
{ {
public $u_action; public $u_action;
public $new_config = array(); public $new_config = array();
protected $c_class; protected $c_class;
protected $db, $user, $cache, $template, $display_vars, $config, $phpbb_root_path, $portal_root_path, $phpbb_admin_path, $phpEx; protected $db, $user, $cache, $template, $display_vars, $config, $phpbb_root_path, $portal_root_path, $phpbb_admin_path, $phpEx;
protected $root_path;
public function __construct() public function __construct()
{ {
global $db, $user, $cache, $template; global $db, $user, $cache, $template;
global $config, $phpbb_root_path, $portal_root_path, $phpbb_admin_path, $phpEx; global $config, $phpbb_root_path, $portal_root_path, $phpbb_admin_path, $phpEx;
$user->add_lang('mods/portal'); $user->add_lang_ext('board3/portal', 'mods/portal');
include($phpbb_root_path . 'portal/includes/constants.' . $phpEx); $this->root_path = $phpbb_root_path . 'ext/board3/portal/';
include($this->root_path . 'portal/includes/constants.' . $phpEx);
$portal_root_path = PORTAL_ROOT_PATH; $portal_root_path = PORTAL_ROOT_PATH;
$this->db = $db; $this->db = $db;
@@ -39,21 +42,22 @@ class acp_portal
$this->config = $config; $this->config = $config;
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->phpbb_admin_path = $phpbb_admin_path; $this->phpbb_admin_path = $phpbb_admin_path;
$this->portal_root_path = $this->root_path . 'portal/';
$this->php_ex = $phpEx; $this->php_ex = $phpEx;
if (!function_exists('column_string_const')) if (!function_exists('column_string_const'))
{ {
include($phpbb_root_path . $portal_root_path . 'includes/functions_modules.' . $this->php_ex); include($this->portal_root_path . 'includes/functions_modules.' . $this->php_ex);
} }
if (!function_exists('mod_version_check')) if (!function_exists('mod_version_check'))
{ {
include($phpbb_root_path . $portal_root_path . 'includes/functions_version_check.' . $this->php_ex); include($this->portal_root_path . 'includes/functions_version_check.' . $this->php_ex);
} }
if(!function_exists('obtain_portal_config')) if(!function_exists('obtain_portal_config'))
{ {
include($phpbb_root_path . $portal_root_path . 'includes/functions.' . $this->php_ex); include($this->portal_root_path . 'includes/functions.' . $this->php_ex);
} }
} }
@@ -105,7 +109,7 @@ class acp_portal
$class = 'portal_' . $module_data['module_classname'] . '_module'; $class = 'portal_' . $module_data['module_classname'] . '_module';
if (!class_exists($class)) if (!class_exists($class))
{ {
include($this->phpbb_root_path . 'portal/modules/portal_' . $module_data['module_classname'] . '.' . $this->php_ex); include($this->root_path . 'portal/modules/portal_' . $module_data['module_classname'] . '.' . $this->php_ex);
} }
if (!class_exists($class)) if (!class_exists($class))
{ {
@@ -115,7 +119,7 @@ class acp_portal
$this->c_class = new $class(); $this->c_class = new $class();
if ($this->c_class->language) if ($this->c_class->language)
{ {
$this->user->add_lang('mods/portal/' . $this->c_class->language); $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $this->c_class->language);
} }
$module_name = $this->user->lang[$this->c_class->name]; $module_name = $this->user->lang[$this->c_class->name];
$display_vars = $this->c_class->get_template_acp($module_id); $display_vars = $this->c_class->get_template_acp($module_id);
@@ -124,7 +128,7 @@ class acp_portal
'MODULE_IMAGE' => $module_data['module_image_src'], 'MODULE_IMAGE' => $module_data['module_image_src'],
'MODULE_IMAGE_WIDTH' => $module_data['module_image_width'], 'MODULE_IMAGE_WIDTH' => $module_data['module_image_width'],
'MODULE_IMAGE_HEIGHT' => $module_data['module_image_height'], 'MODULE_IMAGE_HEIGHT' => $module_data['module_image_height'],
'MODULE_IMAGE_SRC' => ($module_data['module_image_src']) ? $this->phpbb_root_path . 'styles/' . $this->user->theme['theme_path'] . '/theme/images/portal/' . $module_data['module_image_src'] : '', 'MODULE_IMAGE_SRC' => ($module_data['module_image_src']) ? $this->root_path . 'styles/' . $this->user->theme['theme_path'] . '/theme/images/portal/' . $module_data['module_image_src'] : '',
'MODULE_ENABLED' => ($module_data['module_status']) ? true : false, 'MODULE_ENABLED' => ($module_data['module_status']) ? true : false,
'MODULE_SHOW_IMAGE' => (in_array(column_num_string($module_data['module_column']), array('center', 'top', 'bottom'))) ? false : true, 'MODULE_SHOW_IMAGE' => (in_array(column_num_string($module_data['module_column']), array('center', 'top', 'bottom'))) ? false : true,
)); ));
@@ -155,7 +159,7 @@ class acp_portal
else else
{ {
// only show the mod version check if we are on the General Settings page // only show the mod version check if we are on the General Settings page
mod_version_check(); mod_version_check($this->phpbb_root_path, $this->root_path);
} }
$this->new_config = $this->config; $this->new_config = $this->config;
@@ -396,7 +400,7 @@ class acp_portal
if ($add_column) if ($add_column)
{ {
$submit = (isset($_POST['submit'])) ? true : false; $submit = (isset($_POST['submit'])) ? true : false;
$directory = $this->phpbb_root_path . 'portal/modules/'; $directory = $this->root_path . 'portal/modules/';
if ($submit) if ($submit)
{ {
@@ -588,7 +592,7 @@ class acp_portal
} }
else else
{ {
$directory = $this->phpbb_root_path . 'portal/modules/'; $directory = $this->root_path . 'portal/modules/';
$portal_modules = obtain_portal_modules(); $portal_modules = obtain_portal_modules();
@@ -607,7 +611,7 @@ class acp_portal
$this->c_class = new $class(); $this->c_class = new $class();
if ($this->c_class->language) if ($this->c_class->language)
{ {
$this->user->add_lang('mods/portal/' . $this->c_class->language); $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $this->c_class->language);
} }
$template_column = column_num_string($row['module_column']); $template_column = column_num_string($row['module_column']);
@@ -680,7 +684,7 @@ class acp_portal
$this->template->assign_block_vars('modules_' . $template_column, array( $this->template->assign_block_vars('modules_' . $template_column, array(
'MODULE_NAME' => (isset($this->user->lang[$row['module_name']])) ? $this->user->lang[$row['module_name']] : $row['module_name'], 'MODULE_NAME' => (isset($this->user->lang[$row['module_name']])) ? $this->user->lang[$row['module_name']] : $row['module_name'],
'MODULE_IMAGE' => ($row['module_image_src']) ? '<img src="' . $this->phpbb_root_path . 'styles/' . $this->user->theme['theme_path'] . '/theme/images/portal/' . $row['module_image_src'] . '" alt="' . $row['module_name'] . '" />' : '', 'MODULE_IMAGE' => ($row['module_image_src']) ? '<img src="' . $this->root_path . 'styles/' . $this->user->style['style_path'] . '/theme/images/portal/' . $row['module_image_src'] . '" alt="' . $row['module_name'] . '" />' : '',
'MODULE_ENABLED' => ($row['module_status']) ? true : false, 'MODULE_ENABLED' => ($row['module_status']) ? true : false,
'U_DELETE' => $this->u_action . '&amp;module_id=' . $row['module_id'] . '&amp;module_classname=' . $row['module_classname'] . '&amp;action=delete', 'U_DELETE' => $this->u_action . '&amp;module_id=' . $row['module_id'] . '&amp;module_classname=' . $row['module_classname'] . '&amp;action=delete',
@@ -693,10 +697,10 @@ class acp_portal
} }
$this->template->assign_vars(array( $this->template->assign_vars(array(
'ICON_MOVE_LEFT' => '<img src="' . $this->phpbb_admin_path . 'images/icon_left.gif" alt="' . $this->user->lang['MOVE_LEFT'] . '" title="' . $this->user->lang['MOVE_LEFT'] . '" />', 'ICON_MOVE_LEFT' => '<img src="' . $this->root_path . 'adm/images/icon_left.gif" alt="' . $this->user->lang['MOVE_LEFT'] . '" title="' . $this->user->lang['MOVE_LEFT'] . '" />',
'ICON_MOVE_LEFT_DISABLED' => '<img src="' . $this->phpbb_admin_path . 'images/icon_left_disabled.gif" alt="' . $this->user->lang['MOVE_LEFT'] . '" title="' . $this->user->lang['MOVE_LEFT'] . '" />', 'ICON_MOVE_LEFT_DISABLED' => '<img src="' . $this->root_path . 'adm/images/icon_left_disabled.gif" alt="' . $this->user->lang['MOVE_LEFT'] . '" title="' . $this->user->lang['MOVE_LEFT'] . '" />',
'ICON_MOVE_RIGHT' => '<img src="' . $this->phpbb_admin_path . 'images/icon_right.gif" alt="' . $this->user->lang['MOVE_RIGHT'] . '" title="' . $this->user->lang['MOVE_RIGHT'] . '" />', 'ICON_MOVE_RIGHT' => '<img src="' . $this->root_path . 'adm/images/icon_right.gif" alt="' . $this->user->lang['MOVE_RIGHT'] . '" title="' . $this->user->lang['MOVE_RIGHT'] . '" />',
'ICON_MOVE_RIGHT_DISABLED' => '<img src="' . $this->phpbb_admin_path . 'images/icon_right_disabled.gif" alt="' . $this->user->lang['MOVE_RIGHT'] . '" title="' . $this->user->lang['MOVE_RIGHT'] . '" />', 'ICON_MOVE_RIGHT_DISABLED' => '<img src="' . $this->root_path . 'adm/images/icon_right_disabled.gif" alt="' . $this->user->lang['MOVE_RIGHT'] . '" title="' . $this->user->lang['MOVE_RIGHT'] . '" />',
)); ));
} }
@@ -711,9 +715,9 @@ class acp_portal
{ {
trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
} }
include($this->phpbb_root_path . 'portal/includes/functions_upload.' . $this->php_ex); include($this->root_path . 'portal/includes/functions_upload.' . $this->php_ex);
// Default upload path is portal/upload/ // Default upload path is portal/upload/
$upload_path = $this->phpbb_root_path . 'portal/upload/'; $upload_path = $this->root_path . 'portal/upload/';
$portal_upload = new portal_upload($upload_path, $this->u_action); $portal_upload = new portal_upload($upload_path, $this->u_action);
@@ -902,7 +906,7 @@ class acp_portal
$class = 'portal_' . $module_data['module_classname'] . '_module'; $class = 'portal_' . $module_data['module_classname'] . '_module';
if (!class_exists($class)) if (!class_exists($class))
{ {
include($this->phpbb_root_path . 'portal/modules/portal_' . $module_data['module_classname'] . '.' . $this->php_ex); include($this->root_path . 'portal/modules/portal_' . $module_data['module_classname'] . '.' . $this->php_ex);
} }
if (!class_exists($class)) if (!class_exists($class))
{ {
@@ -1014,7 +1018,7 @@ class acp_portal
$class = 'portal_' . $module_data['module_classname'] . '_module'; $class = 'portal_' . $module_data['module_classname'] . '_module';
if (!class_exists($class)) if (!class_exists($class))
{ {
include($this->phpbb_root_path . 'portal/modules/portal_' . $module_data['module_classname'] . '.' . $this->php_ex); include($this->root_path . 'portal/modules/portal_' . $module_data['module_classname'] . '.' . $this->php_ex);
} }
if (!class_exists($class)) if (!class_exists($class))
{ {
@@ -1126,7 +1130,7 @@ class acp_portal
$module_data = $this->db->sql_fetchrow($result); $module_data = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
$directory = $this->phpbb_root_path . 'portal/modules/'; $directory = $this->root_path . 'portal/modules/';
if ($module_data !== false) if ($module_data !== false)
{ {

View File

@@ -91,7 +91,7 @@ class phpbb_ext_board3_portal_controller_main
} }
/** /**
* Extension front handler method. This is called automatically when your extension is accessed * Extension front handler method. This is called automatically when your extension is accessed
* through index.php?ext=example/foobar * through index.php?ext=example/foobar
* @return null * @return null
*/ */
@@ -105,7 +105,7 @@ class phpbb_ext_board3_portal_controller_main
// 1) which extension language folder we're using (it's not smart enough to use its own automatically) // 1) which extension language folder we're using (it's not smart enough to use its own automatically)
// 2) what language file to use // 2) what language file to use
$this->user->add_lang_ext('board3/portal', 'mods/portal'); $this->user->add_lang_ext('board3/portal', 'mods/portal');
/** /**
* get initial data * get initial data
*/ */
@@ -134,7 +134,7 @@ class phpbb_ext_board3_portal_controller_main
{ {
continue; continue;
} }
$class_name = 'portal_' . $row['module_classname'] . '_module'; $class_name = 'portal_' . $row['module_classname'] . '_module';
if (!class_exists($class_name)) if (!class_exists($class_name))
{ {
@@ -146,8 +146,8 @@ class phpbb_ext_board3_portal_controller_main
} }
$module = new $class_name(); $module = new $class_name();
/** /**
* Check for permissions before loading anything * Check for permissions before loading anything
* the default group of a user always defines his/her permission (KISS) * the default group of a user always defines his/her permission (KISS)
*/ */
@@ -156,7 +156,7 @@ class phpbb_ext_board3_portal_controller_main
{ {
continue; continue;
} }
if ($module->language) if ($module->language)
{ {
$this->user->add_lang_ext('board3/portal', 'mods/portal/' . $module->language); $this->user->add_lang_ext('board3/portal', 'mods/portal/' . $module->language);

View File

@@ -19,23 +19,24 @@ if (!defined('IN_PHPBB'))
/** /**
* A copy of Handyman` s MOD version check, to view it on the gallery overview * A copy of Handyman` s MOD version check, to view it on the gallery overview
*/ */
function mod_version_check($return_version = false) function mod_version_check($phpbb_root_path, $root_path, $return_version = false)
{ {
global $user, $template; global $user, $template;
global $phpbb_admin_path, $phpEx; global $phpEx;
if (!function_exists('get_remote_file')) if (!function_exists('get_remote_file'))
{ {
global $phpbb_root_path;
include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
} }
// load version files // load version files
$class_functions = array(); $class_functions = array();
include($phpbb_admin_path . 'mods/board3_portal_check_version.' . $phpEx); include($root_path . 'adm/mods/board3_portal_check_version.' . $phpEx);
$class_name = 'board3_portal_check_version'; $class_name = 'board3_portal_check_version';
$var = call_user_func(array($class_name, 'version')); $version_check = new $class_name();
$var = call_user_func(array($version_check, 'version'));
// Get current and latest version // Get current and latest version
$errstr = ''; $errstr = '';