Ajout d'une extension
This commit is contained in:
95
ext/phpbbstudio/ass/event/blocks_listener.php
Normal file
95
ext/phpbbstudio/ass/event/blocks_listener.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Shop System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\ass\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Shop System: Blocks listener
|
||||
*/
|
||||
class blocks_listener implements EventSubscriberInterface
|
||||
{
|
||||
/** @var \phpbbstudio\ass\operator\blocks */
|
||||
protected $blocks;
|
||||
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbb\language\language */
|
||||
protected $language;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbbstudio\ass\operator\blocks $blocks ASS Blocks object
|
||||
* @param \phpbb\config\config $config Config object
|
||||
* @param \phpbb\language\language $language Language object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(
|
||||
\phpbbstudio\ass\operator\blocks $blocks,
|
||||
\phpbb\config\config $config,
|
||||
\phpbb\language\language $language
|
||||
)
|
||||
{
|
||||
$this->blocks = $blocks;
|
||||
$this->config = $config;
|
||||
$this->language = $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign functions defined in this class to event listeners in the core.
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
static public function getSubscribedEvents()
|
||||
{
|
||||
return ['phpbbstudio.aps.display_blocks' => 'ass_display_blocks'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load language after user set up.
|
||||
*
|
||||
* @event core.user_setup_after
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function ass_display_blocks(\phpbb\event\data $event)
|
||||
{
|
||||
$this->language->add_lang(['ass_common', 'ass_display'], 'phpbbstudio/ass');
|
||||
|
||||
$blocks = $event['page_blocks'];
|
||||
|
||||
$blocks['items'] = [
|
||||
'title' => $this->language->lang('ASS_SHOP'),
|
||||
'auth' => $this->config['ass_enabled'] && $this->config['ass_active'],
|
||||
'blocks' => [],
|
||||
];
|
||||
|
||||
foreach ($this->blocks->get_blocks() as $type => $data)
|
||||
{
|
||||
foreach ($data as $block => $title)
|
||||
{
|
||||
$blocks['items']['blocks'][$block] = [
|
||||
'title' => $this->language->lang($title),
|
||||
'template' => '@phpbbstudio_ass/blocks/' . $block . '.html',
|
||||
'function' => [$this->blocks, $block],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$event['page_blocks'] = $blocks;
|
||||
}
|
||||
}
|
||||
168
ext/phpbbstudio/ass/event/exception_listener.php
Normal file
168
ext/phpbbstudio/ass/event/exception_listener.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Shop System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\ass\event;
|
||||
|
||||
use phpbbstudio\ass\exceptions\shop_inactive_exception;
|
||||
use phpbbstudio\ass\exceptions\shop_item_exception;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use phpbbstudio\ass\exceptions\shop_exception;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Shop System: Exception listener
|
||||
*/
|
||||
class exception_listener implements EventSubscriberInterface
|
||||
{
|
||||
/** @var \phpbb\config\db_text */
|
||||
protected $config_text;
|
||||
|
||||
/** @var \phpbbstudio\ass\helper\controller */
|
||||
protected $controller;
|
||||
|
||||
/** @var \phpbb\language\language */
|
||||
protected $language;
|
||||
|
||||
/** @var \phpbb\textformatter\s9e\renderer */
|
||||
protected $renderer;
|
||||
|
||||
/** @var \phpbb\template\template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb\request\type_cast_helper */
|
||||
protected $type_caster;
|
||||
|
||||
/** @var bool */
|
||||
protected $debug;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\config\db_text $config_text Config text object
|
||||
* @param \phpbbstudio\ass\helper\controller $controller ASS Controller helper object
|
||||
* @param \phpbb\language\language $language Language object
|
||||
* @param \phpbb\textformatter\s9e\renderer $renderer Text formatter renderer object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(
|
||||
\phpbb\config\db_text $config_text,
|
||||
\phpbbstudio\ass\helper\controller $controller,
|
||||
\phpbb\language\language $language,
|
||||
\phpbb\textformatter\s9e\renderer $renderer,
|
||||
\phpbb\template\template $template
|
||||
)
|
||||
{
|
||||
$this->config_text = $config_text;
|
||||
$this->controller = $controller;
|
||||
$this->language = $language;
|
||||
$this->renderer = $renderer;
|
||||
$this->template = $template;
|
||||
|
||||
$this->type_caster = new \phpbb\request\type_cast_helper();
|
||||
$this->debug = defined('DEBUG');
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign functions defined in this class to event listeners in the core.
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
static public function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
KernelEvents::EXCEPTION => 'on_kernel_exception',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle any shop exception.
|
||||
*
|
||||
* @param GetResponseForExceptionEvent $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function on_kernel_exception(GetResponseForExceptionEvent $event)
|
||||
{
|
||||
$exception = $event->getException();
|
||||
|
||||
if ($exception instanceof shop_exception)
|
||||
{
|
||||
$message = $exception->getMessage();
|
||||
$this->type_caster->set_var($message, $message, 'string', true, false);
|
||||
|
||||
$message = $this->language->lang_array($message, $exception->get_parameters());
|
||||
|
||||
// Show <strong> text in bold
|
||||
$message = preg_replace('#<(/?strong)>#i', '<$1>', $message);
|
||||
|
||||
if (!$event->getRequest()->isXmlHttpRequest())
|
||||
{
|
||||
$this->controller->create_shop('shop');
|
||||
|
||||
page_header($this->language->lang('INFORMATION'));
|
||||
|
||||
if ($exception instanceof shop_inactive_exception)
|
||||
{
|
||||
$desc = $this->config_text->get('ass_inactive_desc');
|
||||
$desc = $this->renderer->render(htmlspecialchars_decode($desc, ENT_COMPAT));
|
||||
}
|
||||
|
||||
if ($exception instanceof shop_item_exception)
|
||||
{
|
||||
$desc = $this->language->lang('ASS_ERROR_LOGGED');
|
||||
}
|
||||
|
||||
$this->template->assign_vars([
|
||||
'EXCEPTION_CODE' => $exception->getStatusCode(),
|
||||
'EXCEPTION_TEXT' => $message,
|
||||
'EXCEPTION_DESC' => !empty($desc) ? $desc : '',
|
||||
]);
|
||||
|
||||
$this->template->set_filenames([
|
||||
'body' => 'ass_exception.html',
|
||||
]);
|
||||
|
||||
page_footer(true, false, false);
|
||||
|
||||
$response = new Response($this->template->assign_display('body'), 500);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = [
|
||||
'title' => $this->language->lang('INFORMATION'),
|
||||
];
|
||||
|
||||
if (!empty($message))
|
||||
{
|
||||
$data['message'] = $message;
|
||||
}
|
||||
|
||||
if ($this->debug)
|
||||
{
|
||||
$data['trace'] = $exception->getTrace();
|
||||
}
|
||||
|
||||
$response = new JsonResponse($data, 500);
|
||||
}
|
||||
|
||||
$response->setStatusCode($exception->getStatusCode());
|
||||
$response->headers->add($exception->getHeaders());
|
||||
|
||||
$event->setResponse($response);
|
||||
}
|
||||
}
|
||||
}
|
||||
149
ext/phpbbstudio/ass/event/setup_listener.php
Normal file
149
ext/phpbbstudio/ass/event/setup_listener.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Shop System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\ass\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Shop System: Setup listener
|
||||
*/
|
||||
class setup_listener implements EventSubscriberInterface
|
||||
{
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbbstudio\aps\core\functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var \phpbb\language\language */
|
||||
protected $language;
|
||||
|
||||
/** @var \phpbb\template\template */
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\config\config $config Config object
|
||||
* @param \phpbbstudio\aps\core\functions $functions APS Functions object
|
||||
* @param \phpbb\language\language $language Language object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(
|
||||
\phpbb\config\config $config,
|
||||
\phpbbstudio\aps\core\functions $functions,
|
||||
\phpbb\language\language $language,
|
||||
\phpbb\template\template $template
|
||||
)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->functions = $functions;
|
||||
$this->language = $language;
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign functions defined in this class to event listeners in the core.
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
static public function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'core.user_setup_after' => 'ass_load_lang',
|
||||
'core.page_header_after' => 'ass_setup_links',
|
||||
'core.permissions' => 'ass_setup_permissions',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load language after user set up.
|
||||
*
|
||||
* @event core.user_setup_after
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function ass_load_lang()
|
||||
{
|
||||
$this->language->add_lang('ass_lang', 'phpbbstudio/ass');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up ASS link locations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ass_setup_links()
|
||||
{
|
||||
$locations = array_filter($this->functions->get_link_locations('ass_link_locations'));
|
||||
|
||||
if ($locations)
|
||||
{
|
||||
$this->template->assign_vars(array_combine(array_map(function($key) {
|
||||
return 'S_ASS_' . strtoupper($key);
|
||||
}, array_keys($locations)), $locations));
|
||||
}
|
||||
|
||||
$this->template->assign_vars([
|
||||
'ASS_SHOP_ICON' => (string) $this->config['ass_shop_icon'],
|
||||
'S_ASS_ENABLED' => (bool) $this->config['ass_enabled'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add ASS permissions.
|
||||
*
|
||||
* @event core.permissions
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function ass_setup_permissions(\phpbb\event\data $event)
|
||||
{
|
||||
$categories = $event['categories'];
|
||||
$permissions = $event['permissions'];
|
||||
|
||||
if (empty($categories['phpbb_studio']))
|
||||
{
|
||||
/* Setting up a custom CAT */
|
||||
$categories['phpbb_studio'] = 'ACL_CAT_PHPBB_STUDIO';
|
||||
|
||||
$event['categories'] = $categories;
|
||||
}
|
||||
|
||||
$perms = [
|
||||
'a_ass_inventory',
|
||||
'a_ass_items',
|
||||
'a_ass_files',
|
||||
'a_ass_logs',
|
||||
'a_ass_overview',
|
||||
'a_ass_settings',
|
||||
'u_ass_can_gift',
|
||||
'u_ass_can_purchase',
|
||||
'u_ass_can_receive_gift',
|
||||
'u_ass_can_receive_stock_notifications',
|
||||
'u_ass_can_stack',
|
||||
'u_ass_can_view_inactive_items',
|
||||
'u_ass_can_view_inactive_shop',
|
||||
];
|
||||
|
||||
foreach ($perms as $permission)
|
||||
{
|
||||
$permissions[$permission] = ['language' => 'ACL_' . utf8_strtoupper($permission), 'cat' => 'phpbb_studio'];
|
||||
}
|
||||
|
||||
$event['permissions'] = $permissions;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user