Skip to content

Commit 5dacdb8

Browse files
committed
Add UCP component
1 parent 4c3e3b9 commit 5dacdb8

7 files changed

Lines changed: 209 additions & 0 deletions

File tree

config/skeletons.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ services:
3636
tags:
3737
- { name: phpbb.skeleton.ext.skeleton }
3838

39+
phpbb.skeleton.ext.skeleton.ucp:
40+
class: phpbb\skeleton\skeleton
41+
arguments:
42+
- 'ucp'
43+
- true
44+
- []
45+
- ['ucp/main_info.php', 'ucp/main_module.php', 'styles/prosilver/template/ucp_demo_body.html', 'language/en/info_ucp_demo.php']
46+
tags:
47+
- { name: phpbb.skeleton.ext.skeleton }
48+
3949
phpbb.skeleton.ext.skeleton.migration:
4050
class: phpbb\skeleton\skeleton
4151
arguments:

language/en/common.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
'SKELETON_QUESTION_COMPONENT_HTMLLISTENER_UI' => 'Styles listeners',
7979
'SKELETON_QUESTION_COMPONENT_ACP' => 'Create a sample ACP administration module?',
8080
'SKELETON_QUESTION_COMPONENT_ACP_UI' => 'Administration module (ACP)',
81+
'SKELETON_QUESTION_COMPONENT_UCP' => 'Create a sample UCP user module?',
82+
'SKELETON_QUESTION_COMPONENT_UCP_UI' => 'User control panel (UCP)',
8183
'SKELETON_QUESTION_COMPONENT_MIGRATION' => 'Create sample database migrations?',
8284
'SKELETON_QUESTION_COMPONENT_MIGRATION_UI' => 'Database migration',
8385
'SKELETON_QUESTION_COMPONENT_SERVICE' => 'Create a sample service?',
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
*
4+
* This file is part of the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
* For full copyright and license information, please see
10+
* the docs/CREDITS.txt file.
11+
*
12+
*/
13+
14+
if (!defined('IN_PHPBB'))
15+
{
16+
exit;
17+
}
18+
19+
if (empty($lang) || !is_array($lang))
20+
{
21+
$lang = array();
22+
}
23+
24+
$lang = array_merge($lang, array(
25+
'UCP_DEMO' => 'Settings',
26+
'UCP_DEMO_TITLE' => 'Demo Module',
27+
'UCP_DEMO_USER' => 'Acme user',
28+
'UCP_DEMO_USER_EXPLAIN' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
29+
'UCP_DEMO_SAVED' => 'Settings have been saved successfully!',
30+
));
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
*
4+
* This file is part of the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
* For full copyright and license information, please see
10+
* the docs/CREDITS.txt file.
11+
*
12+
*/
13+
14+
namespace {EXTENSION.vendor_name}\{EXTENSION.extension_name}\migrations;
15+
16+
class install_ucp_module extends \phpbb\db\migration\migration
17+
{
18+
public function effectively_installed()
19+
{
20+
$sql = 'SELECT module_id
21+
FROM ' . $this->table_prefix . "modules
22+
WHERE module_class = 'ucp'
23+
AND module_langname = 'UCP_DEMO_TITLE'";
24+
$result = $this->db->sql_query($sql);
25+
$module_id = (int) $this->db->sql_fetchfield('module_id');
26+
$this->db->sql_freeresult($result);
27+
28+
return !$module_id;
29+
}
30+
31+
static public function depends_on()
32+
{
33+
return array('\{EXTENSION.vendor_name}\{EXTENSION.extension_name}\migration\install_user_chema');
34+
}
35+
36+
public function update_data()
37+
{
38+
return array(
39+
array('module.add', array(
40+
'ucp',
41+
0,
42+
'UCP_DEMO_TITLE'
43+
)),
44+
array('module.add', array(
45+
'ucp',
46+
'UCP_DEMO_TITLE',
47+
array(
48+
'module_basename' => '\{EXTENSION.vendor_name}\{EXTENSION.extension_name}\ucp\main_module',
49+
'modes' => array('settings'),
50+
),
51+
)),
52+
);
53+
}
54+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
&lt;!-- INCLUDE ucp_header.html -->
2+
3+
<form id="ucp" method="post" action="&#123;S_UCP_ACTION}">
4+
<h2>&#123;L_SETTINGS}</h2>
5+
<div class="panel">
6+
<div class="inner">
7+
<fieldset>
8+
<dl>
9+
<dt><label for="user_acme0">&#123;L_UCP_DEMO_USER}&#123;L_COLON}</label><br /><span>&#123;L_UCP_DEMO_USER_EXPLAIN}</span></dt>
10+
<dd><label for="user_acme1"><input type="radio" name="user_acme" id="user_acme1" value="1"&lt;!-- IF S_USER_ACME --> checked="checked"&lt;!-- ENDIF --> /> &#123;L_YES}</label>
11+
<label for="user_acme0"><input type="radio" name="user_acme" id="user_acme0" value="0"&lt;!-- IF not S_USER_ACME --> checked="checked"&lt;!-- ENDIF --> /> &#123;L_NO}</label></dd>
12+
</dl>
13+
</fieldset>
14+
</div>
15+
</div>
16+
<fieldset>
17+
<dl>
18+
<dt>&nbsp;</dt>
19+
<dd><input type="submit" name="submit" id="submit" class="button1" value="&#123;L_SUBMIT}" tabindex="2" />&nbsp;
20+
<input type="reset" value="&#123;L_RESET}" name="reset" class="button2" /></dd>
21+
</dl>
22+
&#123;S_HIDDEN_FIELDS}
23+
&#123;S_FORM_TOKEN}
24+
</fieldset>
25+
</form>
26+
27+
&lt;!-- INCLUDE ucp_footer.html -->

skeleton/ucp/main_info.php.tpl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
*
4+
* This file is part of the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
* For full copyright and license information, please see
10+
* the docs/CREDITS.txt file.
11+
*
12+
*/
13+
14+
namespace {EXTENSION.vendor_name}\{EXTENSION.extension_name}\ucp;
15+
16+
class main_info
17+
{
18+
function module()
19+
{
20+
return array(
21+
'filename' => '\{EXTENSION.vendor_name}\{EXTENSION.extension_name}\ucp\main_module',
22+
'title' => 'UCP_DEMO_TITLE',
23+
'modes' => array(
24+
'settings' => array(
25+
'title' => 'UCP_DEMO',
26+
'auth' => 'ext_{EXTENSION.vendor_name}/{EXTENSION.extension_name}',
27+
'cat' => array('UCP_DEMO_TITLE')
28+
),
29+
),
30+
);
31+
}
32+
}

skeleton/ucp/main_module.php.tpl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
*
4+
* This file is part of the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
* For full copyright and license information, please see
10+
* the docs/CREDITS.txt file.
11+
*
12+
*/
13+
14+
namespace {EXTENSION.vendor_name}\{EXTENSION.extension_name}\ucp;
15+
16+
class main_module
17+
{
18+
var $u_action;
19+
20+
function main($id, $mode)
21+
{
22+
global $db, $request, $template, $user;
23+
24+
$this->tpl_name = 'ucp_demo_body';
25+
$this->page_title = $user->lang('UCP_DEMO_TITLE');
26+
add_form_key('acme/demo');
27+
28+
$data = array(
29+
'user_acme' => $request->variable('user_acme', $user->data['user_acme']),
30+
);
31+
32+
if ($request->is_set_post('submit'))
33+
{
34+
if (!check_form_key('acme/demo'))
35+
{
36+
trigger_error('FORM_INVALID');
37+
}
38+
39+
$sql = 'UPDATE ' . USERS_TABLE . '
40+
SET ' . $db->sql_build_array('UPDATE', $data) . '
41+
WHERE user_id = ' . $user->data['user_id'];
42+
$db->sql_query($sql);
43+
44+
meta_refresh(3, $this->u_action);
45+
$message = $user->lang('UCP_DEMO_SAVED') . '<br /><br />' . $user->lang('RETURN_UCP', '<a href="' . $this->u_action . '">', '</a>');
46+
trigger_error($message);
47+
}
48+
49+
$template->assign_vars(array(
50+
'S_USER_ACME' => $data['user_acme'],
51+
'S_UCP_ACTION' => $this->u_action,
52+
));
53+
}
54+
}

0 commit comments

Comments
 (0)