[feature/module_services] Move links to module services

This commit is contained in:
Marc Alexander
2013-11-16 15:42:22 +01:00
parent 7ef6ca25ba
commit 9a0ad6d1e3
3 changed files with 112 additions and 43 deletions

View File

@@ -158,6 +158,18 @@ services:
tags:
- { name: board3.module }
board3.module.links:
class: \board3\portal\modules\links
arguments:
- @config
- @dbal.conn
- @template
- %core.root_path%
- %core.php_ext%
- @user
tags:
- { name: board3.module }
board3.module.stylechanger:
class: \board3\portal\modules\stylechanger
arguments:

View File

@@ -523,7 +523,7 @@ class v210_beta1 extends \phpbb\db\migration\migration
'module_status' => 1,
),
array(
'module_classname' => 'links',
'module_classname' => '\board3\portal\modules\links',
'module_column' => 3,
'module_order' => 6,
'module_name' => 'PORTAL_LINKS',

View File

@@ -1,24 +1,18 @@
<?php
/**
*
* @package Board3 Portal v2 - Links
* @package Board3 Portal v2.1
* @copyright (c) Board3 Group ( www.board3.de )
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
namespace board3\portal\modules;
/**
* @package Links
*/
class portal_links_module extends \board3\portal\modules\module_base
class links extends module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)
@@ -59,10 +53,49 @@ class portal_links_module extends \board3\portal\modules\module_base
const LINK_INT = 1;
const LINK_EXT = 2;
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\db\driver */
protected $db;
/** @var \phpbb\template */
protected $template;
/** @var php file extension */
protected $php_ext;
/** @var phpbb root path */
protected $phpbb_root_path;
/** @var \phpbb\user */
protected $user;
/**
* Construct a links object
*
* @param \phpbb\config\config $config phpBB config
* @param \phpbb\db\driver $db phpBB db driver
* @param \phpbb\template $template phpBB template
* @param string $phpEx php file extension
* @param string $phpbb_root_path phpBB root path
* @param \phpbb\user $user phpBB user object
*/
public function __construct($config, $db, $template, $phpbb_root_path, $phpEx, $user)
{
$this->config = $config;
$this->db = $db;
$this->template = $template;
$this->php_ext = $phpEx;
$this->phpbb_root_path = $phpbb_root_path;
$this->user = $user;
}
/**
* @inheritdoc
*/
public function get_template_side($module_id)
{
global $config, $template, $phpEx, $phpbb_root_path, $user, $db;
$links = array();
$portal_config = obtain_portal_config();
@@ -76,7 +109,7 @@ class portal_links_module extends \board3\portal\modules\module_base
if($links[$i]['type'] == self::LINK_INT)
{
$links[$i]['url'] = str_replace('&', '&amp;', $links[$i]['url']); // we need to do this in order to prevent XHTML validation errors
$cur_url = append_sid($phpbb_root_path . $links[$i]['url']); // the user should know what kind of file it is
$cur_url = append_sid($this->phpbb_root_path . $links[$i]['url']); // the user should know what kind of file it is
}
else
{
@@ -88,11 +121,11 @@ class portal_links_module extends \board3\portal\modules\module_base
if(!empty($permission_check) || $links[$i]['permission'] == '')
{
$template->assign_block_vars('portallinks', array(
'LINK_TITLE' => (isset($user->lang[$links[$i]['title']])) ? $user->lang[$links[$i]['title']] : $links[$i]['title'],
$this->template->assign_block_vars('portallinks', array(
'LINK_TITLE' => (isset($this->user->lang[$links[$i]['title']])) ? $this->user->lang[$links[$i]['title']] : $links[$i]['title'],
'LINK_URL' => $cur_url,
'MODULE_ID' => $module_id,
'NEW_WINDOW' => ($links[$i]['type'] != self::LINK_INT && $config['board3_links_url_new_window_' . $module_id]) ? true : false,
'NEW_WINDOW' => ($links[$i]['type'] != self::LINK_INT && $this->config['board3_links_url_new_window_' . $module_id]) ? true : false,
));
}
}
@@ -100,6 +133,9 @@ class portal_links_module extends \board3\portal\modules\module_base
return 'links_side.html';
}
/**
* @inheritdoc
*/
public function get_template_acp($module_id)
{
// do not remove this as it is needed in order to run manage_links
@@ -114,12 +150,10 @@ class portal_links_module extends \board3\portal\modules\module_base
}
/**
* API functions
* @inheritdoc
*/
public function install($module_id)
{
global $phpbb_root_path, $db;
$links = array();
$links_titles = array(
@@ -160,6 +194,9 @@ class portal_links_module extends \board3\portal\modules\module_base
return true;
}
/**
* @inheritdoc
*/
public function uninstall($module_id, $db)
{
$del_config = array(
@@ -179,11 +216,17 @@ class portal_links_module extends \board3\portal\modules\module_base
return $db->sql_query($sql);
}
// Manage the menu links
/**
* Manage the links
*
* @param mixed $value Value of input
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
*/
public function manage_links($value, $key, $module_id)
{
global $config, $phpbb_admin_path, $user, $phpEx, $db, $template;
$action = request_var('action', '');
$action = (isset($_POST['add'])) ? 'add' : $action;
$action = (isset($_POST['save'])) ? 'save' : $action;
@@ -194,7 +237,7 @@ class portal_links_module extends \board3\portal\modules\module_base
$links = $this->utf_unserialize($portal_config['board3_links_array_' . $module_id]);
$u_action = append_sid($phpbb_admin_path . 'index.' . $phpEx, 'i=portal&amp;mode=config&amp;module_id=' . $module_id);
$u_action = append_sid('index.' . $this->php_ext, 'i=\board3\portal\acp\portal_module&amp;mode=config&amp;module_id=' . $module_id);
switch ($action)
{
@@ -202,7 +245,7 @@ class portal_links_module extends \board3\portal\modules\module_base
case 'save':
if (!check_form_key('acp_portal'))
{
trigger_error($user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING);
trigger_error($this->user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING);
}
$link_title = utf8_normalize_nfc(request_var('link_title', ' ', true));
@@ -216,12 +259,12 @@ class portal_links_module extends \board3\portal\modules\module_base
$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . '
ORDER BY group_id ASC';
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
$result = $this->db->sql_query($sql);
while($row = $this->db->sql_fetchrow($result))
{
$groups_ary[] = $row['group_id'];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
$link_permissions = array_intersect($link_permission, $groups_ary);
$link_permissions = implode(',', $link_permissions);
@@ -229,18 +272,18 @@ class portal_links_module extends \board3\portal\modules\module_base
// Check for errors
if (!$link_title)
{
trigger_error($user->lang['NO_LINK_TITLE'] . adm_back_link($u_action), E_USER_WARNING);
trigger_error($this->user->lang['NO_LINK_TITLE'] . adm_back_link($u_action), E_USER_WARNING);
}
if (!$link_url)
{
trigger_error($user->lang['NO_LINK_URL'] . adm_back_link($u_action), E_USER_WARNING);
trigger_error($this->user->lang['NO_LINK_URL'] . adm_back_link($u_action), E_USER_WARNING);
}
// overwrite already existing links and make sure we don't try to save a link outside of the normal array size of $links
if (isset($link_id) && $link_id < sizeof($links))
{
$message = $user->lang['LINK_UPDATED'];
$message = $this->user->lang['LINK_UPDATED'];
$links[$link_id] = array(
'title' => $link_title,
@@ -253,7 +296,7 @@ class portal_links_module extends \board3\portal\modules\module_base
}
else
{
$message = $user->lang['LINK_ADDED'];
$message = $this->user->lang['LINK_ADDED'];
$links[] = array(
'title' => $link_title,
@@ -276,7 +319,7 @@ class portal_links_module extends \board3\portal\modules\module_base
if (!isset($link_id) && $link_id >= sizeof($links))
{
trigger_error($user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING);
trigger_error($this->user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING);
}
if (confirm_box(true))
@@ -293,7 +336,7 @@ class portal_links_module extends \board3\portal\modules\module_base
}
else
{
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
confirm_box(false, $this->user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
'link_id' => $link_id,
'action' => 'delete',
)));
@@ -307,7 +350,7 @@ class portal_links_module extends \board3\portal\modules\module_base
if (!isset($link_id) && $link_id >= sizeof($links))
{
trigger_error($user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING);
trigger_error($this->user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING);
}
// make sure we don't try to move a link where it can't be moved
@@ -350,7 +393,7 @@ class portal_links_module extends \board3\portal\modules\module_base
// Edit or add menu item
case 'edit':
case 'add':
$template->assign_vars(array(
$this->template->assign_vars(array(
'LINK_TITLE' => (isset($links[$link_id]['title']) && $action != 'add') ? $links[$link_id]['title'] : '',
'LINK_URL' => (isset($links[$link_id]['url']) && $action != 'add') ? str_replace('&', '&amp;', $links[$link_id]['url']) : '',
@@ -367,16 +410,16 @@ class portal_links_module extends \board3\portal\modules\module_base
$sql = 'SELECT group_id, group_name
FROM ' . GROUPS_TABLE . '
ORDER BY group_id ASC';
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
$result = $this->db->sql_query($sql);
while($row = $this->db->sql_fetchrow($result))
{
$template->assign_block_vars('permission_setting_link', array(
$this->template->assign_block_vars('permission_setting_link', array(
'SELECTED' => (in_array($row['group_id'], $groups_ary)) ? true : false,
'GROUP_NAME' => (isset($user->lang['G_' . $row['group_name']])) ? $user->lang['G_' . $row['group_name']] : $row['group_name'],
'GROUP_NAME' => (isset($this->user->lang['G_' . $row['group_name']])) ? $this->user->lang['G_' . $row['group_name']] : $row['group_name'],
'GROUP_ID' => $row['group_id'],
));
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
return;
@@ -385,8 +428,8 @@ class portal_links_module extends \board3\portal\modules\module_base
for ($i = 0; $i < sizeof($links); $i++)
{
$template->assign_block_vars('links', array(
'LINK_TITLE' => ($action != 'add') ? ((isset($user->lang[$links[$i]['title']])) ? $user->lang[$links[$i]['title']] : $links[$i]['title']) : '',
$this->template->assign_block_vars('links', array(
'LINK_TITLE' => ($action != 'add') ? ((isset($this->user->lang[$links[$i]['title']])) ? $this->user->lang[$links[$i]['title']] : $links[$i]['title']) : '',
'LINK_URL' => ($action != 'add') ? str_replace('&', '&amp;', $links[$i]['url']) : '',
'U_EDIT' => $u_action . '&amp;action=edit&amp;id=' . $i,
@@ -397,12 +440,26 @@ class portal_links_module extends \board3\portal\modules\module_base
}
}
/**
* Update links
*
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
*/
public function update_links($key, $module_id)
{
$this->manage_links('', $key, $module_id);
}
// Unserialize links array
/**
* Unserialize links array
*
* @param string $serial_str Serialized string
*
* @return string Unserialized string
*/
private function utf_unserialize($serial_str)
{
$out = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $serial_str );