Skip to content

Commit

Permalink
First release of the extension
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusWME committed Apr 18, 2016
1 parent 474fbfd commit 320370b
Show file tree
Hide file tree
Showing 12 changed files with 494 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# phpBB---PM-Name-Suggestions
A phpBB extension that suggests usernames when selecting a recipient of a private message.

### How to install
Copy the /pcgf/ folder into your phpBB extension folder /ext/
32 changes: 32 additions & 0 deletions pcgf/pmnamesuggestions/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "pcgf/pmnamesuggestions",
"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.0",
"time": "2016-04-18",
"keywords": ["pm", "private message", "recipient", "username", "suggestion"],
"license": "GPL-2.0",
"authors": [
{
"name": "MarkusWME",
"homepage": "https://github.com/MarkusWME",
"email": "[email protected]",
"role": "Lead Developer"
}
],
"require": {
"php": ">=5.3.3"
},
"extra": {
"display-name": "PM Name Suggestions",
"soft-require": {
"phpbb/phpbb": ">=3.1.*"
},
"version-check": {
"host": "api.pcgf.at",
"directory": "/phpbb",
"filename": "pmnamesuggestions.json"
}
}
}
3 changes: 3 additions & 0 deletions pcgf/pmnamesuggestions/config/routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pcgf_pmnamesuggestions_controller:
path: /pcgf/pmnamesuggestions
defaults: { _controller: pcgf.pmnamesuggestions.controller:getNameSuggestions }
14 changes: 14 additions & 0 deletions pcgf/pmnamesuggestions/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
pcgf.pmnamesuggestions.listener:
class: pcgf\pmnamesuggestions\event\listener
arguments:
- @template
tags:
- { name: event.listener }
pcgf.pmnamesuggestions.controller:
class: pcgf\pmnamesuggestions\controller\controller
arguments:
- @request
- @dbal.conn
- @auth
- @user
115 changes: 115 additions & 0 deletions pcgf/pmnamesuggestions/controller/controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?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\controller;

use Symfony\Component\HttpFoundation\Response;

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

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

/** @var \phpbb\db\driver\factory $db Database object */
protected $db;

/** @var \phpbb\auth\auth $auth Authenticator object */
protected $auth;

/** @var \phpbb\user $user User object */
protected $user;

/**
* Constructor
*
* @access public
* @since 1.0.0
* @param \phpbb\request\request\ $request Request object
* @param \phpbb\db\driver\factory $db Database object
* @param \phpbb\auth\auth $auth Authenticator object
* @param \phpbb\user $user User object
* @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)
{
$this->request = $request;
$this->db = $db;
$this->auth = $auth;
$this->user = $user;
}

/**
* Function to get names matching a given username
*
* @access public
* @since 1.0.0
* @return null
*/
public function getNameSuggestions()
{
$response = new Response();
$response->headers->set('Content-Type', 'text/html');
$response->setContent('');
// Only allow JSON requests
if ($this->request->is_ajax())
{
// Search if a name is given
$search = utf8_strtolower($this->request->variable('search', ''));
if (strlen($search) > 0)
{
$users = '';
$user_count = 0;
$search = $this->db->sql_escape($search);
$query = 'SELECT *
FROM ' . USERS_TABLE . '
WHERE ' . $this->db->sql_in_set('user_type', array(USER_NORMAL, USER_FOUNDER)) . '
AND LOWER(username) LIKE "%' . $search . '%"
ORDER BY CASE WHEN LOWER(username) LIKE "' . $search . '%" THEN 0 ELSE 1 END, username';
$result = $this->db->sql_query($query);
$phpbb_root_path = defined('PHPBB_ROOT_PATH') ? PHPBB_ROOT_PATH : './';
$default_avatar_url = $phpbb_root_path . '/styles/' . $this->user->style['style_path'] . '/theme/images/no_avatar.gif';
if (!file_exists($default_avatar_url))
{
$default_avatar_url = $phpbb_root_path . '/ext/pcgf/pmnamesuggestions/styles/all/theme/images/no_avatar.gif';
}
// Get all users with pm read permission
while ($user = $this->db->sql_fetchrow($result))
{
$this->auth->acl($user);
if ($this->auth->acl_get('u_readpm') > 0)
{
// Add the user to the user list
$avatar_image = phpbb_get_user_avatar($user);
if ($avatar_image == '')
{
$avatar_image = '<img src="' . $default_avatar_url . '"/>';
}
$users .= '<li' . ($user['user_colour'] == '' ? '' : ' style="color: #' . $user['user_colour'] . ';"') . '>' . $avatar_image . $user['username'] . '</li>';
$user_count++;
if ($user_count == self::MAX_USER_COUNT)
{
break;
}
}
}
$this->db->sql_freeresult($result);
$response->setStatusCode(200);
$response->setContent('<ul>' . $users . '</ul>');
}
}
else
{
$response->setStatusCode(400);
}
return $response;
}
}
57 changes: 57 additions & 0 deletions pcgf/pmnamesuggestions/event/listener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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\event;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/** @version 1.0.0 */
class listener implements EventSubscriberInterface
{
/** @var \phpbb\template\template $template Template object */
protected $template;

/**
* Constructor
*
* @access public
* @since 1.0.0
* @param \phpbb\template\template $template Template object
* @return \pcgf\pmnamesuggestions\event\listener The listener object of the extension
*/
public function __construct(\phpbb\template\template $template)
{
$this->template = $template;
}

/**
* Function that returns the subscribed events
*
* @access public
* @since 1.0.0
* @return mixed[] The subscribed event list
*/
static public function getSubscribedEvents()
{
return array(
'core.ucp_pm_compose_modify_data' => 'add_pmnamesuggestion_css',
);
}

/**
* Function that set's the template variable to load the css file when writing a pm
*
* @access public
* @since 1.0.0
* @return null
*/
public function add_pmnamesuggestion_css($event)
{
$this->template->assign_var('PM_NAME_SUGGESTIONS', true);
}
}
40 changes: 40 additions & 0 deletions pcgf/pmnamesuggestions/styles/Mobbern3.1/theme/namesuggestions.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pcgf_pmnamesuggestionlist.pcgf-hidden {
display: none;
}

#pcgf_pmnamesuggestionlist {
background-color: rgb(255, 255, 255);
border: 1px solid rgb(160, 160, 160);
margin-top: 5px;
position: absolute;
width: auto;
z-index: 10;
}

#pcgf_pmnamesuggestionlist > ul {
display: inline-block;
list-style: none;
margin-bottom: 0px;
}

#pcgf_pmnamesuggestionlist > ul > li {
cursor: pointer;
padding: 10px;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
-webkit-user-select: none;
user-select: none;
}

#pcgf_pmnamesuggestionlist > ul > li.selected {
background-color: rgb(200, 200, 200) !important;
}

#pcgf_pmnamesuggestionlist > ul > li > img {
display: inline-block;
height: 20px;
margin-right: 10px;
vertical-align: middle;
width: 20px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- IF PM_NAME_SUGGESTIONS -->
<!-- INCLUDECSS ../theme/namesuggestions.css -->
<!-- ENDIF -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div id="pcgf_pmnamesuggestionlist" class="pcgf-hidden"></div>
<!-- INCLUDEJS js/namesuggestions.js -->
Loading

0 comments on commit 320370b

Please sign in to comment.