Skip to content

Commit

Permalink
Add ACP module that allows to change settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusWME committed Dec 11, 2016
1 parent 66c0ff7 commit 5175771
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 13 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
A phpBB extension that suggests usernames when selecting a recipient of a private message.

## Features
* Display up to five usernames
* Display up to 100 usernames filtered by stated username input
* Display only users which have the permission to read private messages
* Display the avatar images of the users
* Username loading with AJAX
* Change Settings in the ACP
* Suggestion count
* Avatar image size

## Supported styles
* prosilver
Expand All @@ -23,4 +26,9 @@ To install the extension you have to do the following steps:
* phpBB 3.1.*

## External links
[phpBB extension database](https://www.phpbb.com/customise/db/extension/pmnamesuggestions/ "Show extension entry on phpBB.com")
[phpBB extension database](https://www.phpbb.com/customise/db/extension/pmnamesuggestions/ "Show extension entry on phpBB.com")

## Donate
If you like the extension feel free to [Donate with PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SY9JFM9XL9CWQ).

[![Donate with PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SY9JFM9XL9CWQ)
36 changes: 36 additions & 0 deletions pcgf/pmnamesuggestions/acp/pmnamesuggestions_info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* @author MarkusWME <[email protected]>
* @copyright 2016 MarkusWME
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*/

namespace pcgf\pmnamesuggestions\acp;

/** @version 1.1.0 */
class pmnamesuggestions_info
{
/**
* Function that returns module information data
*
* @access public
* @since 1.1.0
* @return array The module information array
*/
public function module()
{
return array(
'filename' => '\pcgf\pmnamesuggestions\acp\pmnamesuggestions_module',
'title' => 'ACP_PCGF_PMNAMESUGGESTIONS',
'version' => '1.1.0',
'modes' => array(
'settings' => array(
'title' => 'ACP_PCGF_PMNAMESUGGESTIONS',
'auth' => 'ext_pcgf/pmnamesuggestions',
'cat' => array('ACP_MESSAGES'),
),
),
);
}
}
56 changes: 56 additions & 0 deletions pcgf/pmnamesuggestions/acp/pmnamesuggestions_module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* @author MarkusWME <[email protected]>
* @copyright 2016 MarkusWME
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*/

namespace pcgf\pmnamesuggestions\acp;

/** @version 1.1.0 */
class pmnamesuggestions_module
{
/** @var string $page_title The title of the page */
public $page_title;

/** @var string $tpl_name The name of the template file */
public $tpl_name;

/** @var object $u_action The user action */
public $u_action;

/**
* Main function of the module
*
* @access public
* @since 1.1.0
*
* @param int $id The module id
* @param string $mode The mode the module is beeing called with
*
* @return null
*/
public function main($id, $mode)
{
global $user, $request, $template, $config;
$this->page_title = $user->lang('ACP_PCGF_PMNAMESUGGESTIONS');
$this->tpl_name = 'acp_pmnamesuggestions_body';
add_form_key('pcgf/pmnamesuggestions');
if ($request->is_set_post('submit'))
{
if (!check_form_key('pcgf/pmnamesuggestions'))
{
trigger_error('FORM_INVALID', E_USER_WARNING);
}
$config->set('pcgf_pmnamesuggestions_user_count', $request->variable('pmnamesuggestions_user_count', 5));
$config->set('pcgf_pmnamesuggestions_avatar_image_size', $request->variable('pmnamesuggestions_avatar_image_size', 20));
trigger_error($user->lang('ACP_PCGF_PMNAMESUGGESTIONS_SETTINGS_SAVED') . adm_back_link($this->u_action));
}
$template->assign_vars(array(
'PCGF_PMNAMESUGGESTIONS_USER_COUNT' => $config['pcgf_pmnamesuggestions_user_count'],
'PCGF_PMNAMESUGGESTIONS_AVATAR_IMAGE_SIZE' => $config['pcgf_pmnamesuggestions_avatar_image_size'],
'U_ACTION' => $this->u_action,
));
}
}
35 changes: 35 additions & 0 deletions pcgf/pmnamesuggestions/adm/style/acp_pmnamesuggestions_body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!-- INCLUDE overall_header.html -->
<h1>{L_ACP_PCGF_PMNAMESUGGESTIONS}</h1>
<p>{L_ACP_PCGF_PMNAMESUGGESTIONS_SETTINGS_EXPLAIN}</p>
<form id="acp_pcgf_pmnamesuggestions_settings" method="post" action="{U_ACTION}">
<fieldset>
<legend>{L_ACP_PCGF_PMNAMESUGGESTIONS_SETTINGS}</legend>
<dl>
<dt>
<label for="pmnamesuggestions_user_count">{L_ACP_PCGF_PMNAMESUGGESTIONS_USER_COUNT}{L_COLON}</label>
<br/>
<span>{L_ACP_PCGF_PMNAMESUGGESTIONS_USER_COUNT_EXPLAIN}</span>
</dt>
<dd>
<input id="pmnamesuggestions_user_count" name="pmnamesuggestions_user_count" type="number" value="{PCGF_PMNAMESUGGESTIONS_USER_COUNT}" min="0" max="100"/>
</dd>
</dl>
<dl>
<dt>
<label for="pmnamesuggestions_avatar_image_size">{L_ACP_PCGF_PMNAMESUGGESTIONS_AVATAR_IMAGE_SIZE}{L_COLON}</label>
<br/>
<span>{L_ACP_PCGF_PMNAMESUGGESTIONS_AVATAR_IMAGE_SIZE_EXPLAIN}</span>
</dt>
<dd>
<input id="pmnamesuggestions_avatar_image_size" name="pmnamesuggestions_avatar_image_size" type="number" value="{PCGF_PMNAMESUGGESTIONS_AVATAR_IMAGE_SIZE}" min="0"/>
<label for="pmnamesuggestions_avatar_image_size">px</label>
</dd>
</dl>
</fieldset>
<p class="submit-buttons">
<input class="button1" type="submit" id="submit" name="submit" value="{L_SUBMIT}"/>&nbsp;
<input class="button2" type="reset" id="reset" name="reset" value="{L_RESET}"/>
{S_FORM_TOKEN}
</p>
</form>
<!-- INCLUDE overall_footer.html -->
4 changes: 2 additions & 2 deletions pcgf/pmnamesuggestions/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"type": "phpbb-extension",
"description": "An extension that suggests usernames when selecting a recipient of a private message",
"homepage": "https://github.com/MarkusWME/phpBB---PM-Name-Suggestions",
"version": "1.0.5",
"time": "2016-12-07",
"version": "1.1.0",
"time": "2016-12-11",
"keywords": ["pm", "private message", "recipient", "username", "suggestion"],
"license": "GPL-2.0",
"authors": [
Expand Down
2 changes: 2 additions & 0 deletions pcgf/pmnamesuggestions/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
arguments:
- @template
- @controller.helper
- @config
tags:
- { name: event.listener }
pcgf.pmnamesuggestions.controller:
Expand All @@ -13,4 +14,5 @@ services:
- @dbal.conn
- @auth
- @user
- @config
- %core.root_path%
14 changes: 8 additions & 6 deletions pcgf/pmnamesuggestions/controller/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@

use Symfony\Component\HttpFoundation\Response;

/** @version 1.0.0 */
/** @version 1.1.0 */
class controller
{
/** @const Max user count */
const MAX_USER_COUNT = 5;

/** @var \phpbb\request\request $request Request object */
protected $request;

Expand All @@ -28,6 +25,9 @@ class controller
/** @var \phpbb\user $user User object */
protected $user;

/** @var \phpbb\config\config $config Configuration object */
protected $config;

/** @var string $phpbb_root_path The forum root path */
protected $phpbb_root_path;

Expand All @@ -41,16 +41,18 @@ class controller
* @param \phpbb\db\driver\factory $db Database object
* @param \phpbb\auth\auth $auth Authenticator object
* @param \phpbb\user $user User object
* @param \phpbb\config\config $config Configuration object
* @param string $phpbb_root_path The forum root path
*
* @return \pcgf\pmnamesuggestions\controller\controller The controller object of the extension
*/
public function __construct(\phpbb\request\request $request, \phpbb\db\driver\factory $db, \phpbb\auth\auth $auth, \phpbb\user $user, $phpbb_root_path)
public function __construct(\phpbb\request\request $request, \phpbb\db\driver\factory $db, \phpbb\auth\auth $auth, \phpbb\user $user, \phpbb\config\config $config, $phpbb_root_path)
{
$this->request = $request;
$this->db = $db;
$this->auth = $auth;
$this->user = $user;
$this->config = $config;
$this->phpbb_root_path = $phpbb_root_path;
}

Expand Down Expand Up @@ -103,7 +105,7 @@ public function getNameSuggestions()
}
array_push($users, array('username' => $user['username'], 'user' => get_username_string('no_profile', $user['user_id'], $user['username'], $user['user_colour']), 'avatar' => $avatar_image));
$user_count++;
if ($user_count == self::MAX_USER_COUNT)
if ($user_count == $this->config['pcgf_pmnamesuggestions_user_count'])
{
break;
}
Expand Down
11 changes: 8 additions & 3 deletions pcgf/pmnamesuggestions/event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/** @version 1.0.0 */
/** @version 1.1.0 */
class listener implements EventSubscriberInterface
{
/** @var \phpbb\template\template $template Template object */
Expand All @@ -19,6 +19,9 @@ class listener implements EventSubscriberInterface
/** @var \phpbb\controller\helper $helper Helper object */
protected $helper;

/** @var \phpbb\config\config $config Configuration object */
protected $config;

/**
* Constructor
*
Expand All @@ -27,13 +30,15 @@ class listener implements EventSubscriberInterface
*
* @param \phpbb\template\template $template Template object
* @param \phpbb\controller\helper $helper Helper object
* @param \phpbb\config\config $config Configuration object
*
* @return \pcgf\pmnamesuggestions\event\listener The listener object of the extension
*/
public function __construct(\phpbb\template\template $template, \phpbb\controller\helper $helper)
public function __construct(\phpbb\template\template $template, \phpbb\controller\helper $helper, \phpbb\config\config $config)
{
$this->template = $template;
$this->helper = $helper;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -62,7 +67,7 @@ public function add_pmnamesuggestion_css($event)
$this->template->assign_vars(array(
'PM_NAME_SUGGESTIONS' => true,
'PCGF_PM_NAME_SUGGESTION_URL' => $this->helper->route('pcgf_pmnamesuggestions_controller'),
'PCGF_PM_NAME_SOGGESTION_IMAGE_SIZE' => 20,
'PCGF_PM_NAME_SOGGESTION_IMAGE_SIZE' => $this->config['pcgf_pmnamesuggestions_avatar_image_size'],
));
}
}
30 changes: 30 additions & 0 deletions pcgf/pmnamesuggestions/language/de/info_acp_pmnamesuggestions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* @author MarkusWME <[email protected]>
* @copyright 2016 MarkusWME
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
* @version 1.1.0
*/

if (!defined('IN_PHPBB'))
{
exit;
}

if (empty($lang) || !is_array($lang))
{
$lang = array();
}

// Merging language data for the ACP with the other language data
$lang = array_merge($lang, array(
'ACP_PCGF_PMNAMESUGGESTIONS' => 'PN Namensvorschläge',
'ACP_PCGF_PMNAMESUGGESTIONS_AVATAR_IMAGE_SIZE' => 'Größe der Avatar-Bilder',
'ACP_PCGF_PMNAMESUGGESTIONS_AVATAR_IMAGE_SIZE_EXPLAIN' => 'Legt die Breite und die Höhe des Avatar-Bildes auf den angegebenen Wert fest. Um kein Avatar-Bild anzeigen zu lassen kann der Wert auf 0 gesetzt werden.',
'ACP_PCGF_PMNAMESUGGESTIONS_SETTINGS' => 'Einstellungen',
'ACP_PCGF_PMNAMESUGGESTIONS_SETTINGS_EXPLAIN' => 'Hier kannst du einige Einstellungen für die PN Namensvorschläge anpassen.',
'ACP_PCGF_PMNAMESUGGESTIONS_SETTINGS_SAVED' => 'Die Einstellungen wurden erfolgreich gespeichert!',
'ACP_PCGF_PMNAMESUGGESTIONS_USER_COUNT' => 'Anzahl der Vorschläge',
'ACP_PCGF_PMNAMESUGGESTIONS_USER_COUNT_EXPLAIN' => 'Die maximale Anzahl der vorzuschlagenden Benutzer (Werte zwischen 0 und 100 sind erlaubt).',
));
30 changes: 30 additions & 0 deletions pcgf/pmnamesuggestions/language/en/info_acp_pmnamesuggestions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* @author MarkusWME <[email protected]>
* @copyright 2016 MarkusWME
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
* @version 1.1.0
*/

if (!defined('IN_PHPBB'))
{
exit;
}

if (empty($lang) || !is_array($lang))
{
$lang = array();
}

// Merging language data for the ACP with the other language data
$lang = array_merge($lang, array(
'ACP_PCGF_PMNAMESUGGESTIONS' => 'PM Name Suggestions',
'ACP_PCGF_PMNAMESUGGESTIONS_AVATAR_IMAGE_SIZE' => 'Avatar image size',
'ACP_PCGF_PMNAMESUGGESTIONS_AVATAR_IMAGE_SIZE_EXPLAIN' => 'Sets width and height of the avatar image to the given value. To hide the avatar image you can set the value to 0.',
'ACP_PCGF_PMNAMESUGGESTIONS_SETTINGS' => 'Settings',
'ACP_PCGF_PMNAMESUGGESTIONS_SETTINGS_EXPLAIN' => 'Here you can adjust the settings for PM Name Suggestions.',
'ACP_PCGF_PMNAMESUGGESTIONS_SETTINGS_SAVED' => 'The settings have been saved successfully!',
'ACP_PCGF_PMNAMESUGGESTIONS_USER_COUNT' => 'Suggestion count',
'ACP_PCGF_PMNAMESUGGESTIONS_USER_COUNT_EXPLAIN' => 'The maximum count of suggested users (values between 0 and 100 are allowed).',
));
Loading

0 comments on commit 5175771

Please sign in to comment.