From 59a37a06aca7c848b5922478de1434e2ae63bb15 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 5 Oct 2012 15:33:02 +0200 Subject: [PATCH] Add basic files for being an extension --- root/composer.json | 55 +++++++++++++ root/controller.php | 182 ++++++++++++++++++++++++++++++++++++++++++++ root/ext.php | 9 +++ 3 files changed, 246 insertions(+) create mode 100644 root/composer.json create mode 100644 root/controller.php create mode 100644 root/ext.php diff --git a/root/composer.json b/root/composer.json new file mode 100644 index 00000000..20328ff0 --- /dev/null +++ b/root/composer.json @@ -0,0 +1,55 @@ +{ + "name": "board3/portal", + "type": "phpbb3-extension", + "description": "Adds a portal with several blocks to your forum. You can change the settings, move the blocks, add new blocks and more in the ACP.", + "homepage": "http://www.board3.de", + "version": "2.1.0-dev", + "time": "2012-10-05 10:40:01", + "licence": "GPL-2.0", + "authors": [{ + "name": "Marc Alexander", + "username": "marc1706", + "email": "admin@m-a-styles.de", + "homepage": "http://www.m-a-styles.de", + "role": "Lead Developer" + }, + { + "name": "Joas Schilling", + "username": "nickvergessen", + "email": "nickvergessen@gmx.de", + "homepage": "http://mods.flying-bits.org", + "role": "Developer" + }, + { + "name": "Kevin", + "username": "saint_hh", + "homepage": "http://www.board3.de", + "role": "Developer" + }, + { + "name": "Ice", + "username": "avaren", + "homepage": "http://www.board3.de", + "role": "Developer" + }, + { + "name": "Christian", + "username": "Christian_N", + "homepage": "http://www.phpbb-projekt.de", + "role": "Developer" + }, + { + "name": "Walter", + "username": "Redbull254", + "email": "w.bobeth@digitalfotografie-foren.de", + "homepage": "http://www.digitalfotografie-foren.de", + "role": "Developer" + }], + "require": { + "php": ">=5.2", + "phpbb": "3.1.0-dev" + }, + "extra": { + "display-name": "Board3 Portal" + } +} diff --git a/root/controller.php b/root/controller.php new file mode 100644 index 00000000..e383a908 --- /dev/null +++ b/root/controller.php @@ -0,0 +1,182 @@ +root_path = $phpbb_root_path . '/ext/board3/portal/portal/'; + + $this->check_permission(); + // We defined the phpBB objects in __construct() and can use them in the rest of our class like this + //echo 'Welcome, ' . $this->user->data['username']; + + // The following takes two arguments: + // 1) which extension language folder we're using (it's not smart enough to use its own automatically) + // 2) what language file to use + $this->user->add_lang_ext('board3/portal', 'mods/portal'); + + //$this->template->set_ext_dir_prefix($phpbb_root_path . 'ext/board3/portal/'); + + $this->display_modules(); + + // foobar_body.html is in ./ext/foobar/example/styles/prosilver/template/foobar_body.html + $this->template->set_filenames(array( + 'body' => 'portal/portal_body.html' + )); + + // And we assign template variables the same as before as well + $this->template->assign_var('MESSAGE', 'Yes, this is hard-coded language, which should still be avoided in virtually all cases.'); + + // And now to output the page. + page_header($this->user->lang('PORTAL')); + page_footer(); + } + + // check if user should be able to access this page + private function check_permission() + { + global $config, $auth, $phpbb_root_path, $phpEx; + + if (!isset($config['board3_enable']) || !$config['board3_enable'] || !$auth->acl_get('u_view_portal')) + { + redirect(append_sid($phpbb_root_path . 'index.' . $phpEx)); + } + } + + /** + * Display the portal modules + * + * @return: true if page can be display, false if there are no modules to display + */ + private function display_modules() + { + global $template, $phpbb_root_path; + + /** + * get initial data + */ + $portal_config = obtain_portal_config(); + $portal_modules = obtain_portal_modules(); + + /** + * set up column_count array + * with this we can hide unneeded parts of the portal + */ + $module_count = array( + 'total' => 0, + 'top' => 0, + 'left' => 0, + 'center' => 0, + 'right' => 0, + 'bottom' => 0, + ); + + /** + * start assigning block vars + */ + foreach ($portal_modules as $row) + { + if($row['module_status'] == B3_MODULE_DISABLED) + { + continue; + } + + $class_name = 'portal_' . $row['module_classname'] . '_module'; + if (!class_exists($class_name)) + { + include("{$this->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 + * the default group of a user always defines his/her permission (KISS) + */ + $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_ext('board3/portal', 'mods/portal/' . $module->language); + } + if ($row['module_column'] == column_string_num('left') && $config['board3_left_column']) + { + $template_module = $module->get_template_side($row['module_id']); + $template_column = 'left'; + ++$module_count['left']; + } + if ($row['module_column'] == column_string_num('center')) + { + $template_module = $module->get_template_center($row['module_id']); + $template_column = 'center'; + ++$module_count['center']; + } + if ($row['module_column'] == column_string_num('right') && $config['board3_right_column']) + { + $template_module = $module->get_template_side($row['module_id']); + $template_column = 'right'; + ++$module_count['right']; + } + if ($row['module_column'] == column_string_num('top')) + { + $template_module = $module->get_template_center($row['module_id']); + ++$module_count['top']; + } + if ($row['module_column'] == column_string_num('bottom')) + { + $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' => $this->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'], + 'IMAGE_WIDTH' => $row['module_image_width'], + 'IMAGE_HEIGHT' => $row['module_image_height'], + )); + } + else + { + $template->assign_block_vars('modules_' . column_num_string($row['module_column']), array( + 'TEMPLATE_FILE' => 'portal/modules/' . $template_module, + 'IMAGE_SRC' => $this->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); + } + return sizeof($portal_modules); + } + +} diff --git a/root/ext.php b/root/ext.php new file mode 100644 index 00000000..4b5fd6f1 --- /dev/null +++ b/root/ext.php @@ -0,0 +1,9 @@ +