Ajout d'une extension
This commit is contained in:
276
ext/phpbbstudio/ass/helper/controller.php
Normal file
276
ext/phpbbstudio/ass/helper/controller.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?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\helper;
|
||||
|
||||
use phpbbstudio\ass\entity\category;
|
||||
use phpbbstudio\ass\entity\item;
|
||||
use phpbbstudio\ass\exceptions\shop_inactive_exception;
|
||||
use phpbb\exception\http_exception;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Shop System: Controller helper
|
||||
*/
|
||||
class controller
|
||||
{
|
||||
/** @var \phpbbstudio\aps\core\functions */
|
||||
protected $aps_functions;
|
||||
|
||||
/** @var \phpbb\auth\auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbb\config\db_text */
|
||||
protected $config_text;
|
||||
|
||||
/** @var \phpbb\controller\helper */
|
||||
protected $helper;
|
||||
|
||||
/** @var \phpbb\language\language */
|
||||
protected $language;
|
||||
|
||||
/** @var \phpbbstudio\ass\operator\category */
|
||||
protected $operator_cat;
|
||||
|
||||
/** @var \phpbbstudio\ass\helper\router */
|
||||
protected $router;
|
||||
|
||||
/** @var \phpbb\template\template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbbstudio\aps\core\functions $aps_functions APS Functions object
|
||||
* @param \phpbb\auth\auth $auth Auth object
|
||||
* @param \phpbb\config\config $config Config object
|
||||
* @param \phpbb\config\db_text $config_text Config text object
|
||||
* @param \phpbb\controller\helper $helper Controller helper object
|
||||
* @param \phpbb\language\language $language Language object
|
||||
* @param \phpbbstudio\ass\operator\category $operator_cat Category operator object
|
||||
* @param \phpbbstudio\ass\helper\router $router Router helper object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(
|
||||
\phpbbstudio\aps\core\functions $aps_functions,
|
||||
\phpbb\auth\auth $auth,
|
||||
\phpbb\config\config $config,
|
||||
\phpbb\config\db_text $config_text,
|
||||
\phpbb\controller\helper $helper,
|
||||
\phpbb\language\language $language,
|
||||
\phpbbstudio\ass\operator\category $operator_cat,
|
||||
router $router,
|
||||
\phpbb\template\template $template,
|
||||
\phpbb\user $user
|
||||
)
|
||||
{
|
||||
$this->aps_functions = $aps_functions;
|
||||
$this->auth = $auth;
|
||||
$this->config = $config;
|
||||
$this->config_text = $config_text;
|
||||
$this->helper = $helper;
|
||||
$this->language = $language;
|
||||
$this->operator_cat = $operator_cat;
|
||||
$this->router = $router;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the shop is enabled and active.
|
||||
*
|
||||
* @return void
|
||||
* @throws http_exception
|
||||
* @throws shop_inactive_exception
|
||||
* @access public
|
||||
*/
|
||||
public function check_shop()
|
||||
{
|
||||
if (!$this->config['ass_enabled'])
|
||||
{
|
||||
throw new http_exception(404, 'PAGE_NOT_FOUND');
|
||||
}
|
||||
|
||||
$this->language->add_lang('ass_common', 'phpbbstudio/ass');
|
||||
$this->language->add_lang('aps_display', 'phpbbstudio/aps');
|
||||
|
||||
if (!$this->config['ass_active'] && !$this->auth->acl_get('u_ass_can_view_inactive_shop'))
|
||||
{
|
||||
throw new shop_inactive_exception(409, 'ASS_SHOP_INACTIVE');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and set up the shop.
|
||||
*
|
||||
* @param string $mode The shop mode (shop|inventory|history)
|
||||
* @param category|null $category The category entity
|
||||
* @param item|null $item The item entity
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function create_shop($mode, category $category = null, item $item = null)
|
||||
{
|
||||
$this->create_shop_crumbs($mode, $category, $item);
|
||||
$this->create_shop_navbar($mode, $category);
|
||||
|
||||
$this->template->assign_vars([
|
||||
'S_ASS_INVENTORY' => $mode === 'inventory',
|
||||
'S_ASS_SHOP' => $mode === 'shop',
|
||||
'S_CAN_GIFT' => $this->auth->acl_get('u_ass_can_gift') && $this->config['ass_gift_enabled'],
|
||||
'S_CAN_PURCHASE' => $this->auth->acl_get('u_ass_can_purchase') && $this->user->data['is_registered'],
|
||||
'S_RECEIVE_GIFT' => $this->auth->acl_get('u_ass_can_receive_gift'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and set up the shop navigation.
|
||||
*
|
||||
* @param string $mode The shop mode (shop|inventory|history)
|
||||
* @param category|null $category The category entity
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function create_shop_navbar($mode, category $category = null)
|
||||
{
|
||||
$categories = $this->operator_cat->get_categories(true);
|
||||
|
||||
$title = $mode === 'shop' ? 'ASS_SHOP_INDEX' : 'ASS_INVENTORY';
|
||||
$route = $mode === 'shop' ? 'phpbbstudio_ass_shop' : 'phpbbstudio_ass_inventory';
|
||||
|
||||
$this->template->assign_block_vars('ass_shop_categories', [
|
||||
'ID' => 0,
|
||||
'TITLE' => $this->language->lang($title),
|
||||
'ICON' => 'fa-bookmark',
|
||||
'S_SELECTED' => $category === null,
|
||||
'U_VIEW' => $this->helper->route($route),
|
||||
]);
|
||||
|
||||
/** @var category $cat */
|
||||
foreach ($categories as $cat)
|
||||
{
|
||||
$this->template->assign_block_vars('ass_shop_categories', [
|
||||
'ID' => $cat->get_id(),
|
||||
'TITLE' => $cat->get_title(),
|
||||
'ICON' => $cat->get_icon(),
|
||||
'S_SELECTED' => $category !== null && $cat->get_id() === $category->get_id(),
|
||||
'U_VIEW' => $this->router->category($cat->get_slug(), $mode),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and set up the shop breadcrumbs.
|
||||
*
|
||||
* @param string $mode The shop mode (shop|inventory|history)
|
||||
* @param category|null $category The category entity
|
||||
* @param item|null $item The item entity
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function create_shop_crumbs($mode, category $category = null, item $item = null)
|
||||
{
|
||||
$title = $mode === 'shop' ? 'ASS_SHOP_INDEX' : 'ASS_INVENTORY';
|
||||
$route = $mode === 'shop' ? 'phpbbstudio_ass_shop' : 'phpbbstudio_ass_inventory';
|
||||
|
||||
$this->template->assign_block_vars_array('navlinks', [
|
||||
[
|
||||
'FORUM_NAME' => $this->aps_functions->get_name(),
|
||||
'U_VIEW_FORUM' => $this->helper->route('phpbbstudio_aps_display'),
|
||||
],
|
||||
[
|
||||
'FORUM_NAME' => $this->language->lang($title),
|
||||
'U_VIEW_FORUM' => $this->helper->route($route),
|
||||
],
|
||||
]);
|
||||
|
||||
if ($mode === 'history')
|
||||
{
|
||||
$this->template->assign_block_vars('navlinks', [
|
||||
'FORUM_NAME' => $this->language->lang('ASS_HISTORY'),
|
||||
'U_VIEW_FORUM' => $this->helper->route('phpbbstudio_ass_history'),
|
||||
]);
|
||||
}
|
||||
|
||||
if ($category instanceof category)
|
||||
{
|
||||
$this->template->assign_block_vars('navlinks', [
|
||||
'FORUM_NAME' => $category->get_title(),
|
||||
'U_VIEW_FORUM' => $this->router->category($category->get_slug(), $mode),
|
||||
]);
|
||||
}
|
||||
|
||||
if ($item instanceof item)
|
||||
{
|
||||
$this->template->assign_block_vars('navlinks', [
|
||||
'FORUM_NAME' => $item->get_title(),
|
||||
'U_VIEW_FORUM' => $this->router->item($item->get_category_slug(), $item->get_slug()),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up and assign carousel variables.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function setup_carousel()
|
||||
{
|
||||
$this->template->assign_vars([
|
||||
'SHOP_CAROUSEL_ARROWS' => (bool) $this->config['ass_carousel_arrows'],
|
||||
'SHOP_CAROUSEL_DOTS' => (bool) $this->config['ass_carousel_dots'],
|
||||
'SHOP_CAROUSEL_FADE' => (bool) $this->config['ass_carousel_fade'],
|
||||
'SHOP_CAROUSEL_PLAY' => (bool) $this->config['ass_carousel_play'],
|
||||
'SHOP_CAROUSEL_PLAY_SPEED' => (int) $this->config['ass_carousel_play_speed'],
|
||||
'SHOP_CAROUSEL_SPEED' => (int) $this->config['ass_carousel_speed'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up and assign panel variables.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function setup_panels()
|
||||
{
|
||||
$panels = ['featured', 'sale', 'featured_sale', 'recent', 'limited', 'random'];
|
||||
$options = [
|
||||
'icon' => '',
|
||||
'icon_colour' => 'icon-',
|
||||
'banner_colour' => 'shop-panel-icon-',
|
||||
'banner_size' => 'shop-panel-icon-',
|
||||
];
|
||||
|
||||
foreach ($panels as $panel)
|
||||
{
|
||||
if ($this->config["ass_panel_{$panel}_icon"])
|
||||
{
|
||||
$icon = '';
|
||||
|
||||
foreach ($options as $option => $prefix)
|
||||
{
|
||||
$icon .= " {$prefix}{$this->config["ass_panel_{$panel}_{$option}"]}";
|
||||
}
|
||||
|
||||
$this->template->assign_var('SHOP_PANEL_' . utf8_strtoupper($panel) . '_ICON', $icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
471
ext/phpbbstudio/ass/helper/files.php
Normal file
471
ext/phpbbstudio/ass/helper/files.php
Normal file
@@ -0,0 +1,471 @@
|
||||
<?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\helper;
|
||||
|
||||
use phpbb\exception\runtime_exception;
|
||||
use phpbb\finder;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Shop System: Files helper
|
||||
*/
|
||||
class files
|
||||
{
|
||||
/** @var \phpbb\cache\service */
|
||||
protected $cache;
|
||||
|
||||
/** @var \phpbb\files\factory */
|
||||
protected $factory;
|
||||
|
||||
/** @var \phpbb\finder */
|
||||
protected $finder;
|
||||
|
||||
/** @var \phpbb\filesystem\filesystem */
|
||||
protected $filesystem;
|
||||
|
||||
/** @var string phpBB root path */
|
||||
protected $root_path;
|
||||
|
||||
/** @var array Shop files modes */
|
||||
protected $modes = ['files', 'images'];
|
||||
|
||||
/** @var string Shop files mode */
|
||||
protected $mode = '';
|
||||
|
||||
/** @var array File extensions */
|
||||
protected $extensions = [
|
||||
'archives' => ['7z', 'ace', 'bz2', 'gtar', 'gz', 'rar', 'tar', 'tgz', 'torrent', 'zip'],
|
||||
'images' => ['gif', 'jpeg', 'jpg', 'png', 'tga', 'tif', 'tiff'],
|
||||
'documents' => ['ai', 'doc', 'docm', 'docx', 'dot', 'dotm', 'dotx', 'odg', 'odp', 'ods', 'odt', 'pdf', 'ppt', 'pptm', 'pptx', 'ps', 'rtf', 'xls', 'xlsb', 'xlsm', 'xlsx'],
|
||||
'text' => ['c', 'cpp', 'csv', 'diz', 'h', 'hpp', 'ini', 'js', 'log', 'txt', 'xml'],
|
||||
'other' => ['mp3', 'mpeg', 'mpg', 'ogg', 'ogm'],
|
||||
];
|
||||
|
||||
/** @var array File extensions specific icons */
|
||||
protected $specific_icons = [
|
||||
'powerpoint-o' => ['ppt', 'pptm', 'pptx'],
|
||||
'excel-o' => ['csv', 'xls', 'xlsb', 'xlsm', 'xlsx'],
|
||||
'pdf-o' => ['pdf'],
|
||||
'audio-o' => ['mp3'],
|
||||
'movie-o' => ['mpeg', 'mpg', 'ogg', 'ogm'],
|
||||
'code-o' => ['c', 'cpp', 'h', 'hpp', 'ini', 'js'],
|
||||
];
|
||||
|
||||
/** @var array File extensions icons */
|
||||
protected $icons = [
|
||||
'archives' => 'file-archive-o',
|
||||
'images' => 'file-image-o',
|
||||
'documents' => 'file-word-o',
|
||||
'text' => 'file-text-o',
|
||||
'other' => 'file-o',
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\cache\service $cache Cache object
|
||||
* @param \phpbb\files\factory $factory Files factory object
|
||||
* @param \phpbb\filesystem\filesystem $filesystem Filesystem object
|
||||
* @param string $root_path phpBB root path
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(
|
||||
\phpbb\cache\service $cache,
|
||||
\phpbb\files\factory $factory,
|
||||
\phpbb\filesystem\filesystem $filesystem,
|
||||
$root_path
|
||||
)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->factory = $factory;
|
||||
$this->filesystem = $filesystem;
|
||||
|
||||
$this->root_path = $root_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the shop files modes.
|
||||
*
|
||||
* @return array The shop files modes
|
||||
* @access public
|
||||
*/
|
||||
public function get_modes()
|
||||
{
|
||||
return (array) $this->modes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the shop files mode.
|
||||
*
|
||||
* @param string $mode The shop files mode
|
||||
* @return self $this This object for chaining calls
|
||||
* @access public
|
||||
*/
|
||||
public function set_mode($mode)
|
||||
{
|
||||
$this->mode = $mode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the finder instance.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function set_finder()
|
||||
{
|
||||
if ($this->finder === null)
|
||||
{
|
||||
$this->finder = new finder($this->filesystem, $this->root_path, $this->cache);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file size of a shop file.
|
||||
*
|
||||
* @param string $directory The shop file directory
|
||||
* @param string $file The shop file
|
||||
* @return int
|
||||
* @access public
|
||||
*/
|
||||
public function get_file_size($directory, $file)
|
||||
{
|
||||
$path = $this->get_path($directory, true, $file);
|
||||
|
||||
return $this->filesystem->exists($path) ? filesize($path) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file modification time of a shop file.
|
||||
*
|
||||
* @param string $directory The shop file directory
|
||||
* @param string $file The shop file
|
||||
* @return int
|
||||
* @access public
|
||||
*/
|
||||
public function get_file_time($directory, $file)
|
||||
{
|
||||
$path = $this->get_path($directory, true, $file);
|
||||
|
||||
return $this->filesystem->exists($path) ? filemtime($path) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file icon of a shop file.
|
||||
*
|
||||
* @param string $file The shop file
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
public function get_file_icon($file)
|
||||
{
|
||||
$extension = pathinfo($file, PATHINFO_EXTENSION);
|
||||
|
||||
foreach ($this->specific_icons as $icon => $extensions)
|
||||
{
|
||||
if (in_array($extension, $extensions))
|
||||
{
|
||||
return $icon;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->extensions as $type => $extensions)
|
||||
{
|
||||
if (in_array($extension, $extensions))
|
||||
{
|
||||
return $this->icons[$type];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->icons['other'];
|
||||
}
|
||||
|
||||
/**
|
||||
* View a shop file directory.
|
||||
*
|
||||
* @param string $directory The shop file directory
|
||||
* @return array The files and folders in the shop file directory
|
||||
* @access public
|
||||
*/
|
||||
public function view($directory = '')
|
||||
{
|
||||
$files = [];
|
||||
$folders = [];
|
||||
|
||||
$needle = $this->get_path($directory);
|
||||
$target = $this->get_path($directory, false);
|
||||
|
||||
$this->set_finder();
|
||||
|
||||
foreach ($this->finder->core_path($target)->get_files() as $path)
|
||||
{
|
||||
$file = $this->clean_path($path, $needle);
|
||||
|
||||
if ($this->is_htaccess($file))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->is_not_nested($file))
|
||||
{
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->finder->core_path($target)->get_directories() as $path)
|
||||
{
|
||||
$folder = $this->clean_path($path, $needle);
|
||||
|
||||
if ($this->is_not_nested($folder))
|
||||
{
|
||||
$folders[] = $folder;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->mode === 'files')
|
||||
{
|
||||
$this->create_htaccess();
|
||||
}
|
||||
|
||||
return [
|
||||
'files' => $files,
|
||||
'folders' => $folders,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a shop file.
|
||||
*
|
||||
* @param string $directory The shop file directory
|
||||
* @param string $image The shop file image
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
public function select($directory, $image = '')
|
||||
{
|
||||
$files = [];
|
||||
|
||||
$needle = $this->get_path($directory);
|
||||
$target = $this->get_path($directory, false);
|
||||
|
||||
$this->set_finder();
|
||||
|
||||
foreach ($this->finder->core_path($target)->get_files() as $path)
|
||||
{
|
||||
$file = $this->clean_path($path, $needle);
|
||||
|
||||
if ($this->is_not_nested($path))
|
||||
{
|
||||
$files[] = [
|
||||
'NAME' => $file,
|
||||
'S_SELECTED' => $path === $image,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a shop file.
|
||||
*
|
||||
* @param string $directory The shop file directory
|
||||
* @param string $folder The shop file folder
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function add($directory, $folder)
|
||||
{
|
||||
if ($folder === '')
|
||||
{
|
||||
throw new runtime_exception('ASS_ERROR_TOO_SHORT', [0, 0]);
|
||||
}
|
||||
|
||||
if (!preg_match('/^[^!"#$%&*\'()+,.\/\\\\:;<=>?@\\[\\]^`{|}~ ]*$/', $folder))
|
||||
{
|
||||
throw new runtime_exception('ASS_ERROR_ILLEGAL_CHARS');
|
||||
}
|
||||
|
||||
$target = $this->get_path($directory, true, $folder);
|
||||
|
||||
if ($this->filesystem->exists($target))
|
||||
{
|
||||
throw new runtime_exception('ASS_ERROR_NOT_UNIQUE', [$folder]);
|
||||
}
|
||||
|
||||
$this->filesystem->mkdir($target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a shop file from an <input> element.
|
||||
*
|
||||
* @param string $directory The shop file directory
|
||||
* @param string $input_name The name of the <input> element
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function upload($directory, $input_name)
|
||||
{
|
||||
/** @var \phpbb\files\upload $upload */
|
||||
$upload = $this->factory->get('files.upload');
|
||||
|
||||
if (!$upload->is_valid($input_name))
|
||||
{
|
||||
throw new runtime_exception('FORM_INVALID');
|
||||
}
|
||||
|
||||
$file = $upload
|
||||
->set_allowed_extensions($this->get_extensions())
|
||||
->handle_upload('files.types.form', $input_name);
|
||||
|
||||
$upload->common_checks($file);
|
||||
|
||||
if ($file->error)
|
||||
{
|
||||
throw new runtime_exception(implode('<br>', array_unique($file->error)));
|
||||
}
|
||||
|
||||
if ($this->exists($directory, $file->get('realname')))
|
||||
{
|
||||
throw new runtime_exception('ASS_ERROR_NOT_UNIQUE', [$file->get('realname')]);
|
||||
}
|
||||
|
||||
$file->move_file($this->get_path($directory, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a shop file exists.
|
||||
*
|
||||
* @param string $directory The shop file directory
|
||||
* @param string $file The shop file
|
||||
* @return bool Whether or not the file exists
|
||||
* @access public
|
||||
*/
|
||||
public function exists($directory, $file = '')
|
||||
{
|
||||
return (bool) $this->filesystem->exists($this->get_path($directory, true, $file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a shop file from a given path.
|
||||
*
|
||||
* @param string $path Path to a shop file
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function delete($path)
|
||||
{
|
||||
$this->filesystem->remove($this->get_path($path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a path to a shop file.
|
||||
*
|
||||
* @param string $directory The shop file directory
|
||||
* @param bool $root Whether or not to include the phpBB root path
|
||||
* @param string $file The shop file
|
||||
* @return string The shop file path
|
||||
* @access public
|
||||
*/
|
||||
public function get_path($directory, $root = true, $file = '')
|
||||
{
|
||||
$root_path = $root ? $this->root_path : '';
|
||||
|
||||
$directory = $directory ? "/{$directory}" : '';
|
||||
$file = $file ? "/{$file}" : '';
|
||||
|
||||
return "{$root_path}{$this->mode}/aps{$directory}{$file}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file extensions for a mode.
|
||||
*
|
||||
* @return array The file extensions
|
||||
* @access public
|
||||
*/
|
||||
public function get_extensions()
|
||||
{
|
||||
if ($this->mode === 'images')
|
||||
{
|
||||
return (array) $this->extensions[$this->mode];
|
||||
}
|
||||
else
|
||||
{
|
||||
$extensions = [];
|
||||
|
||||
foreach ($this->extensions as $array)
|
||||
{
|
||||
$extensions = array_merge($extensions, $array);
|
||||
}
|
||||
|
||||
return (array) $extensions;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean the needle from a path.
|
||||
*
|
||||
* @param string $path The path
|
||||
* @param string $needle The needle
|
||||
* @return string
|
||||
* @access protected
|
||||
*/
|
||||
protected function clean_path($path, $needle)
|
||||
{
|
||||
return trim(str_replace($needle, '', $path), '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a path is nested.
|
||||
*
|
||||
* @param string $path The path
|
||||
* @return bool Whether or not the path is nested
|
||||
* @access protected
|
||||
*/
|
||||
protected function is_not_nested($path)
|
||||
{
|
||||
return strpos($path, '/') === false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a file is the ".htaccess" file.
|
||||
*
|
||||
* @param string $file The file
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
protected function is_htaccess($file)
|
||||
{
|
||||
return $this->mode === 'files' && $file === '.htaccess';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ".htaccess" file.
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function create_htaccess()
|
||||
{
|
||||
$htaccess = $this->root_path . $this->mode . '/aps/.htaccess';
|
||||
|
||||
if (!$this->filesystem->exists($htaccess))
|
||||
{
|
||||
$this->filesystem->dump_file($htaccess,
|
||||
"<Files *>
|
||||
Order Allow,Deny
|
||||
Deny from All
|
||||
</Files>");
|
||||
}
|
||||
}
|
||||
}
|
||||
213
ext/phpbbstudio/ass/helper/log.php
Normal file
213
ext/phpbbstudio/ass/helper/log.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?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\helper;
|
||||
|
||||
use phpbbstudio\ass\entity\item;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Shop System: Log helper
|
||||
*/
|
||||
class log
|
||||
{
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
protected $db;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/** @var string Categories table */
|
||||
protected $categories_table;
|
||||
|
||||
/** @var string Items table */
|
||||
protected $items_table;
|
||||
|
||||
/** @var string Logs table */
|
||||
protected $logs_table;
|
||||
|
||||
/** @var string Users table */
|
||||
protected $users_table;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\db\driver\driver_interface $db Database object
|
||||
* @param \phpbb\user $user User object
|
||||
* @param string $categories_table Categories table
|
||||
* @param string $items_table Items table
|
||||
* @param string $logs_table Logs table
|
||||
* @param string $users_table Users table
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(
|
||||
\phpbb\db\driver\driver_interface $db,
|
||||
\phpbb\user $user,
|
||||
$categories_table,
|
||||
$items_table,
|
||||
$logs_table,
|
||||
$users_table
|
||||
)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->user = $user;
|
||||
|
||||
$this->categories_table = $categories_table;
|
||||
$this->items_table = $items_table;
|
||||
$this->logs_table = $logs_table;
|
||||
$this->users_table = $users_table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a log entry to the shop logs table.
|
||||
*
|
||||
* @param item $item The shop item
|
||||
* @param bool $purchase Whether it is a purchase/gift or an activation
|
||||
* @param double $points_sum The points sum (cost of the purchase/gift)
|
||||
* @param int $recipient_id The recipient identifier
|
||||
* @param double $points_old The user's old points total
|
||||
* @param double $points_new The user's new points total
|
||||
* @param int $time The log time
|
||||
* @return bool Whether or not the log was successfully added
|
||||
* @access public
|
||||
*/
|
||||
public function add(item $item, $purchase, $points_sum = 0.00, $recipient_id = 0, $points_old = 0.00, $points_new = 0.00, $time = 0)
|
||||
{
|
||||
$time = $time ? $time : time();
|
||||
|
||||
if ($purchase && $points_sum)
|
||||
{
|
||||
$points_old = $points_old ? $points_old : $this->user->data['user_points'];
|
||||
$points_new = $points_new ? $points_new : $points_old - $points_sum;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'log_ip' => (string) $this->user->ip,
|
||||
'log_time' => (int) $time,
|
||||
'points_old' => (double) $points_old,
|
||||
'points_sum' => (double) $points_sum,
|
||||
'points_new' => (double) $points_new,
|
||||
'item_purchase' => (bool) $purchase,
|
||||
'item_id' => (int) $item->get_id(),
|
||||
'category_id' => (int) $item->get_category(),
|
||||
'user_id' => (int) $this->user->data['user_id'],
|
||||
'recipient_id' => (int) $recipient_id,
|
||||
];
|
||||
|
||||
$sql = 'INSERT INTO ' . $this->logs_table . ' ' . $this->db->sql_build_array('INSERT', $data);
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
return (bool) $this->db->sql_affectedrows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the shop log entries for a specific user.
|
||||
*
|
||||
* @param string $sql_where The SQL WHERE statement
|
||||
* @param string $sql_order The SQL ORDER BY statement
|
||||
* @param string $sql_dir The SQL ORDER BY direction
|
||||
* @param int $limit The amount of entries to return
|
||||
* @param int $start The offset from where to return entries
|
||||
* @param int $user_id The user identifier
|
||||
* @return array The shop log entries
|
||||
* @access public
|
||||
*/
|
||||
public function get_user_logs($sql_where, $sql_order, $sql_dir, $limit, $start, $user_id = 0)
|
||||
{
|
||||
if ($user_id)
|
||||
{
|
||||
$user_where = '(l.user_id = ' . (int) $user_id . ' OR l.recipient_id = ' . (int) $user_id . ')';
|
||||
|
||||
$sql_where = $sql_where ? $user_where . ' AND ' . $sql_where : $user_where;
|
||||
}
|
||||
|
||||
$sql_array = [
|
||||
'SELECT' => 'l.*, i.item_title, c.category_title,
|
||||
u.username, u.user_colour,
|
||||
r.username as recipient_name, r.user_colour as recipient_colour',
|
||||
'FROM' => [$this->logs_table => 'l'],
|
||||
'LEFT_JOIN' => [
|
||||
[
|
||||
'FROM' => [$this->categories_table => 'c'],
|
||||
'ON' => 'l.category_id = c.category_id',
|
||||
],
|
||||
[
|
||||
'FROM' => [$this->items_table => 'i'],
|
||||
'ON' => 'l.item_id = i.item_id',
|
||||
],
|
||||
[
|
||||
'FROM' => [$this->users_table => 'r'],
|
||||
'ON' => 'l.recipient_id = r.user_id',
|
||||
],
|
||||
[
|
||||
'FROM' => [$this->users_table => 'u'],
|
||||
'ON' => 'l.user_id = u.user_id',
|
||||
],
|
||||
],
|
||||
'WHERE' => $sql_where,
|
||||
'ORDER_BY' => "{$sql_order} {$sql_dir}",
|
||||
];
|
||||
|
||||
$sql = $this->db->sql_build_query('SELECT', $sql_array);
|
||||
$result = $this->db->sql_query_limit($sql, $limit, $start);
|
||||
$rowset = $this->db->sql_fetchrowset($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return (array) $rowset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the shop log entries count for a specific user.
|
||||
*
|
||||
* @param string $sql_where The SQL WHERE statement
|
||||
* @param int $user_id The user identifier
|
||||
* @return int The shop log entries count
|
||||
* @access public
|
||||
*/
|
||||
public function get_user_logs_count($sql_where, $user_id = 0)
|
||||
{
|
||||
if ($user_id)
|
||||
{
|
||||
$user_where = 'l.user_id = ' . (int) $user_id;
|
||||
|
||||
$sql_where = $sql_where ? $user_where . ' AND ' . $sql_where : $user_where;
|
||||
}
|
||||
|
||||
$sql_array = [
|
||||
'SELECT' => 'COUNT(l.log_id) as count',
|
||||
'FROM' => [$this->logs_table => 'l'],
|
||||
'WHERE' => $sql_where,
|
||||
];
|
||||
|
||||
$sql = $this->db->sql_build_query('SELECT', $sql_array);
|
||||
$result = $this->db->sql_query($sql);
|
||||
$count = $this->db->sql_fetchfield('count');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return (int) $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete shop log entries.
|
||||
*
|
||||
* @param bool $all Delete all log entries
|
||||
* @param array $ids The log entry identifiers
|
||||
* @return bool Whether or not any entries were deleted
|
||||
* @access public
|
||||
*/
|
||||
public function delete($all, array $ids)
|
||||
{
|
||||
$sql = 'DELETE FROM ' . $this->logs_table
|
||||
. (!$all ? ' WHERE ' . $this->db->sql_in_set('log_id', $ids) : '');
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
return (bool) $this->db->sql_affectedrows();
|
||||
}
|
||||
}
|
||||
137
ext/phpbbstudio/ass/helper/router.php
Normal file
137
ext/phpbbstudio/ass/helper/router.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?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\helper;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Shop System: Router helper
|
||||
*/
|
||||
class router
|
||||
{
|
||||
/** @var \phpbb\controller\helper */
|
||||
protected $helper;
|
||||
|
||||
/** @var string phpBB root path */
|
||||
protected $root_path;
|
||||
|
||||
/** @var string php File extension */
|
||||
protected $php_ext;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\controller\helper $helper Controller helper object
|
||||
* @param string $root_path phpBB root path
|
||||
* @param string $php_ext php File extension
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(\phpbb\controller\helper $helper, $root_path, $php_ext)
|
||||
{
|
||||
$this->helper = $helper;
|
||||
|
||||
$this->root_path = $root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for a category.
|
||||
*
|
||||
* @param string $category_slug The category slug
|
||||
* @param string $mode The mode
|
||||
* @return string The URL
|
||||
* @access public
|
||||
*/
|
||||
public function category($category_slug, $mode = 'category')
|
||||
{
|
||||
$mode = $mode === 'inventory' ? $mode : 'category';
|
||||
|
||||
return $this->helper->route("phpbbstudio_ass_{$mode}", ['category_slug' => $category_slug]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for the inventory.
|
||||
*
|
||||
* @param string $category_slug The category slug
|
||||
* @param string $item_slug The item slug
|
||||
* @param int $index The item index
|
||||
* @param string $action The action
|
||||
* @param array $params Additional parameters
|
||||
* @return string The URL
|
||||
* @access public
|
||||
*/
|
||||
public function inventory($category_slug = '', $item_slug = '', $index = 1, $action = '', array $params = [])
|
||||
{
|
||||
$params = array_merge(['category_slug' => $category_slug, 'item_slug' => $item_slug, 'index' => $index, 'action' => $action], $params);
|
||||
|
||||
return $this->helper->route('phpbbstudio_ass_inventory', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for the gift action.
|
||||
*
|
||||
* @param string $category_slug The category slug
|
||||
* @param string $item_slug The item slug
|
||||
* @return string The URL
|
||||
* @access public
|
||||
*/
|
||||
public function gift($category_slug, $item_slug)
|
||||
{
|
||||
return $this->helper->route('phpbbstudio_ass_gift', ['category_slug' => $category_slug, 'item_slug' => $item_slug]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for an item.
|
||||
*
|
||||
* @param string $category_slug The category slug
|
||||
* @param string $item_slug The item slug
|
||||
* @return string The URL
|
||||
* @access public
|
||||
*/
|
||||
public function item($category_slug, $item_slug)
|
||||
{
|
||||
return $this->helper->route('phpbbstudio_ass_item', ['category_slug' => $category_slug, 'item_slug' => $item_slug]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for the purchase action.
|
||||
*
|
||||
* @param string $category_slug The category slug
|
||||
* @param string $item_slug The item slug
|
||||
* @return string The URL
|
||||
* @access public
|
||||
*/
|
||||
public function purchase($category_slug, $item_slug)
|
||||
{
|
||||
return $this->helper->route('phpbbstudio_ass_purchase', ['category_slug' => $category_slug, 'item_slug' => $item_slug]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for a 'regular' phpBB page (viewtopic, viewforum, etc..).
|
||||
*
|
||||
* @param string $page The phpBB page
|
||||
* @param string|array $params The parameters
|
||||
* @param bool $is_amp Whether it is & or &
|
||||
* @param bool $ajax Whether the request is AJAX or not
|
||||
* @return string The URL
|
||||
* @access public
|
||||
*/
|
||||
public function regular($page, $params = '', $is_amp = true, $ajax = false)
|
||||
{
|
||||
if ($ajax)
|
||||
{
|
||||
return append_sid(generate_board_url() . "/{$page}.{$this->php_ext}", $params, $is_amp, false, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return append_sid("{$this->root_path}{$page}.{$this->php_ext}", $params, $is_amp, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
183
ext/phpbbstudio/ass/helper/time.php
Normal file
183
ext/phpbbstudio/ass/helper/time.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?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\helper;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Shop System: Time helper
|
||||
*/
|
||||
class time
|
||||
{
|
||||
/** @var \phpbb\language\language */
|
||||
protected $language;
|
||||
|
||||
/** @var string The board's default timezone */
|
||||
protected $timezone;
|
||||
|
||||
/** @var string The default datetime format */
|
||||
protected $format = 'd/m/Y H:i';
|
||||
|
||||
const WEEK = 604800;
|
||||
const DAY = 86400;
|
||||
const HOUR = 3600;
|
||||
const MINUTE = 60;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\config\config $config Config object
|
||||
* @param \phpbb\language\language $language Language object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(
|
||||
\phpbb\config\config $config,
|
||||
\phpbb\language\language $language
|
||||
)
|
||||
{
|
||||
$this->language = $language;
|
||||
$this->timezone = $config['board_timezone'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the board's default timezone.
|
||||
*
|
||||
* @return string The board's default timezone
|
||||
* @access public
|
||||
*/
|
||||
public function get_timezone()
|
||||
{
|
||||
return $this->timezone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default datetime format.
|
||||
*
|
||||
* @return string The default datetime format
|
||||
* @access public
|
||||
*/
|
||||
public function get_format()
|
||||
{
|
||||
return $this->format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and get the UNIX timestamp from a formatted string.
|
||||
*
|
||||
* @param string $string The formatted string
|
||||
* @return int
|
||||
* @access public
|
||||
*/
|
||||
public function create_from_format($string)
|
||||
{
|
||||
$tz = date_default_timezone_get();
|
||||
|
||||
date_default_timezone_set($this->timezone);
|
||||
|
||||
$unix = date_timestamp_get(\DateTime::createFromFormat($this->format, $string));
|
||||
|
||||
date_default_timezone_set($tz);
|
||||
|
||||
return (int) $unix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn an amount of seconds into a readable string.
|
||||
*
|
||||
* For example "1 day, 2 hours and 5 minutes"
|
||||
*
|
||||
* @param int $seconds The amount of seconds
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
public function seconds_to_string($seconds)
|
||||
{
|
||||
$time = [
|
||||
'ASS_DAYS' => 0,
|
||||
'ASS_HOURS' => 0,
|
||||
'ASS_MINUTES' => 0,
|
||||
'ASS_SECONDS' => 0,
|
||||
];
|
||||
|
||||
$time['ASS_DAYS'] = floor($seconds / self::DAY);
|
||||
|
||||
$seconds = ($seconds % self::DAY);
|
||||
$time['ASS_HOURS'] = floor($seconds / self::HOUR);
|
||||
|
||||
$seconds %= self::HOUR;
|
||||
$time['ASS_MINUTES'] = floor($seconds / self::MINUTE);
|
||||
|
||||
$seconds %= self::MINUTE;
|
||||
$time['ASS_SECONDS'] = $seconds;
|
||||
|
||||
$time = array_filter($time);
|
||||
$count = count($time);
|
||||
$index = 1;
|
||||
$string = '';
|
||||
|
||||
foreach ($time as $key => $value)
|
||||
{
|
||||
if ($index !== 1)
|
||||
{
|
||||
$string .= $this->language->lang($index === $count ? 'ASS_AND' : 'COMMA_SEPARATOR');
|
||||
}
|
||||
|
||||
$string .= $this->language->lang($key, $value);
|
||||
|
||||
$index++;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current time is within two UNIX timestamps.
|
||||
*
|
||||
* @param int $start The first UNIX timestamp
|
||||
* @param int $until The second UNIX timestamp
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
public function within($start, $until)
|
||||
{
|
||||
return (bool) ($start < time() && time() < $until);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current time is after a provided UNIX timestamp + additional seconds.
|
||||
*
|
||||
* An example would be that the provided timestamp is a item purchase time
|
||||
* and the additional seconds are the amount of seconds before the item is non-refundable.
|
||||
*
|
||||
* If the additional seconds is 0, it means the item is already non-refundable.
|
||||
*
|
||||
* @param int $time The provided UNIX timestamp
|
||||
* @param int $seconds The additional seconds
|
||||
* @return bool Whether or not the time has expired
|
||||
* @access public
|
||||
*/
|
||||
public function has_expired($time, $seconds)
|
||||
{
|
||||
return (bool) (!empty($seconds) && $time + $seconds <= time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current time is within a week of a provided UNIX timestamp + additional seconds.
|
||||
*
|
||||
* @param int $time The provided UNIX timestamp
|
||||
* @param int $seconds The additional seconds
|
||||
* @return bool Whether or not the time will expire within a week
|
||||
* @access public
|
||||
*/
|
||||
public function will_expire($time, $seconds)
|
||||
{
|
||||
return (bool) (!empty($seconds) && ($time + $seconds) >= (time() - self::WEEK));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user