Fixed some minor issues in main menu block;

Added links block;
This commit is contained in:
Marc Alexander
2010-10-05 20:11:18 +00:00
parent 7b089f1513
commit 38da0b16f5
10 changed files with 511 additions and 55 deletions

View File

@@ -17,20 +17,14 @@
<form id="acp_portal_links" method="post" action="{U_ACTION}">
<fieldset>
<legend>{L_ACP_PORTAL_LINKS}</legend>
<legend>{L_ACP_PORTAL_MENU_LINK}</legend>
<dl>
<dt><label for="link_title">{L_LINK_TITLE}:</label></dt>
<dd><input name="link_title" type="text" id="link_title" value="{LINK_TITLE}" maxlength="255" /></dd>
</dl>
<dl>
<dt><label for="link_is_cat">{L_LINK_IS_CAT}:</label></dt>
<dd><label><input onchange="dE('url', -1)" type="radio" class="radio" name="link_is_cat" value="1" id="link_is_cat"<!-- IF S_LINK_IS_CAT --> checked="checked"<!-- ENDIF --> />{L_YES}</label>
<label><input onchange="dE('url', 1)" type="radio" class="radio" name="link_is_cat" value="0"<!-- IF not S_LINK_IS_CAT --> checked="checked"<!-- ENDIF --> /> {L_NO}</label></dd>
</dl>
<!-- IF S_LINK_IS_CAT --><div id="url" style="display: none;"><!-- ELSE --><div id="url"><!-- ENDIF -->
<dl>
<dt>
<label for="link_tpye">{L_ACP_PORTAL_MENU_TYPE}:</label><br />
<label for="link_type">{L_ACP_PORTAL_MENU_TYPE}:</label><br />
<span>{L_ACP_PORTAL_MENU_TYPE_EXP}</span>
</dt>
<dd>
@@ -39,11 +33,25 @@
</dd>
</dl>
<dl>
<dt><label for="link_url">{L_LINK_URL}:</label></dt>
<dt>
<label for="link_url">{L_ACP_PORTAL_MENU_URL}:</label><br />
<span>{L_ACP_PORTAL_MENU_URL_EXP}</span>
</dt>
<dd><input name="link_url" type="text" id="link_url" value="{LINK_URL}" maxlength="255" /></dd>
</dl>
</div>
<dl>
<dt>
<label for="permission-setting">{L_ACP_PORTAL_MENU_PERMISSION}:</label><br />
<span>{L_ACP_PORTAL_MENU_PERMISSION_EXP}</span>
</dt>
<dd>
<select id="permission-setting" size="10" multiple="multiple" name="permission-setting[]">
<!-- BEGIN permission_setting -->
<option value="{permission_setting.GROUP_ID}"<!-- IF permission_setting.SELECTED -->selected="selected"<!-- ENDIF -->>{permission_setting.GROUP_NAME}</option>
<!-- END permission_setting -->
</select>
</dd>
</dl>
<p class="submit-buttons">
<input type="hidden" name="action" value="save" />
@@ -97,14 +105,21 @@
<a href="{links.U_EDIT}">{ICON_EDIT}</a> <a href="{links.U_DELETE}">{ICON_DELETE}</a>
</td>
</tr>
<!-- BEGINELSE -->
<tr class="row1">
<td style="text-align: center;" colspan="3">{L_LINKS_NO_LINKS}</td>
</tr>
<!-- END links -->
</tbody>
</table>
<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}" />
</p>
{S_FORM_TOKEN}
</fieldset>
</form>
<!-- ENDIF -->
<!-- INCLUDE overall_footer.html -->
<!-- INCLUDE overall_footer.html -->

View File

@@ -112,6 +112,10 @@
<a href="{links.U_EDIT}">{ICON_EDIT}</a> <a href="{links.U_DELETE}">{ICON_DELETE}</a>
</td>
</tr>
<!-- BEGINELSE -->
<tr class="row1">
<td style="text-align: center;" colspan="3">{L_MENU_NO_LINKS}</td>
</tr>
<!-- END links -->
</tbody>
</table>

View File

@@ -0,0 +1,43 @@
<?php
/**
* @package Portal - Links
* @version $Id: portal_main_menu_module.php 700 2010-10-03 09:22:47Z marc1706 $
* @copyright (c) 2009, 2010 Board3 Portal Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
/**
* DO NOT CHANGE
*/
if (!defined('IN_PHPBB'))
{
exit;
}
if (empty($lang) || !is_array($lang))
{
$lang = array();
}
// DEVELOPERS PLEASE NOTE
//
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
//
// Placeholders can now contain order information, e.g. instead of
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
// translators to re-order the output of data while ensuring it remains correct
//
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
// equally where a string contains only two placeholders which are used to wrap text
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
$lang = array_merge($lang, array(
'PORTAL_LINKS' => 'Links',
'LINKS_NO_LINKS' => 'No links',
// ACP
'ACP_PORTAL_LINKS' => 'Link Settings',
'ACP_PORTAL_LINKS_EXP' => 'Customize the links listed in the links block',
// @todo: Add necessary language variables
));
?>

View File

@@ -39,6 +39,7 @@ $lang = array_merge($lang, array(
'M_TERMS' => 'Terms of use',
'M_PRV' => 'Privacy policy',
'M_SEARCH' => 'Search',
'MENU_NO_LINKS' => 'No links',
// ACP
'ACP_PORTAL_MENU' => 'Menu settings',

View File

@@ -0,0 +1,411 @@
<?php
/**
* @package Portal - Links
* @version $Id$
* @copyright (c) 2009, 2010 Board3 Portal Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* @package Links
*/
class portal_links_module
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)
* top 1
* left 2
* center 4
* right 8
* bottom 16
*/
var $columns = 10;
/**
* Default modulename
*/
var $name = 'PORTAL_LINKS';
/**
* Default module-image:
* file must be in "{T_THEME_PATH}/images/portal/"
*/
var $image_src = 'portal_links.png';
/**
* module-language file
* file must be in "language/{$user->lang}/mods/portal/"
*/
var $language = 'portal_links_module';
/**
* custom acp template
* file must be in "adm/style/portal/"
*/
var $custom_acp_tpl = 'acp_portal_links';
function get_template_side($module_id)
{
global $config, $template, $phpEx, $phpbb_root_path, $user, $db;
$links = array();
$portal_config = obtain_portal_config();
$links = $this->utf_unserialize($portal_config['board3_links_array_' . $module_id]);
// get user's groups
$sql = 'SELECT group_id
FROM ' . USER_GROUP_TABLE . '
WHERE user_id = ' . (int) $user->data['user_id'] . '
ORDER BY group_id ASC';
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{
$groups_ary[] = $row['group_id'];
}
$db->sql_freeresult($result);
for ($i = 0; $i < sizeof($links); $i++)
{
if($links[$i]['type'] == B3_LINKS_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
}
else
{
$cur_url = $links[$i]['url'];
}
$cur_permissions = explode(',', $links[$i]['permission']);
$permission_check = array_intersect($groups_ary, $cur_permissions);
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'],
'LINK_URL' => $cur_url,
));
}
}
return 'links_side.html';
}
function get_template_acp($module_id)
{
// do not remove this as it is needed in order to run manage_links
return array(
'title' => 'ACP_PORTAL_LINKS',
'vars' => array(
'legend1' => 'ACP_PORTAL_MENU',
'board3_links_' . $module_id => array('lang' => 'ACP_PORTAL_MENU_MANAGE', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'manage_links', 'submit' => 'update_links'),
),
);
}
/**
* API functions
*/
function install($module_id)
{
global $phpbb_root_path, $db;
$links = array();
$links_titles = array(
'Board3.de',
'phpBB.com',
);
$links_types = array(
B3_LINKS_EXT,
B3_LINKS_EXT,
);
$links_urls = array(
'http://www.board3.de/',
'http://www.phpbb.com/',
);
$links_permissions = array(
'',
'',
);
foreach($links_urls as $i => $url)
{
$links[] = array(
'title' => $links_titles[$i],
'url' => $links_urls[$i],
'type' => $links_types[$i],
'permission' => $links_permissions[$i],
);
}
$board3_menu_array = serialize($links);
set_portal_config('board3_links_array_' . $module_id, $board3_menu_array);
set_config('board3_links_' . $module_id, '');
return true;
}
function uninstall($module_id)
{
global $db;
$del_config = array(
'board3_links_array_' . $module_id,
);
$sql = 'DELETE FROM ' . PORTAL_CONFIG_TABLE . '
WHERE ' . $db->sql_in_set('config_name', $del_config);
$del_config = array(
'board3_links_' . $module_id,
);
$sql = 'DELETE FROM ' . CONFIG_TABLE . '
WHERE ' . $db->sql_in_set('config_name', $del_config);
return $db->sql_query($sql);
}
// Manage the menu links
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;
$link_id = request_var('id', 99999999); // 0 will trigger unwanted behavior, therefore we set a number we should never reach
$portal_config = obtain_portal_config();
$links = array();
$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);
switch ($action)
{
// Save changes
case 'save':
if (!check_form_key('acp_portal'))
{
trigger_error($user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING);
}
$link_title = utf8_normalize_nfc(request_var('link_title', ' ', true));
$link_type = request_var('link_type', 2); // default to B3_LINK_EXT, no categories in Links block
$link_url = request_var('link_url', ' ');
$link_url = str_replace('&amp;', '&', $link_url);
$link_permission = request_var('permission-setting', array(0 => ''));
$groups_ary = array();
// get groups and check if the selected groups actually exist
$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . '
ORDER BY group_id ASC';
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{
$groups_ary[] = $row['group_id'];
}
$db->sql_freeresult($result);
$link_permissions = array_intersect($link_permission, $groups_ary);
$link_permissions = implode(',', $link_permissions);
// Check for errors
if (!$link_title)
{
trigger_error($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);
}
// 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'];
$links[$link_id] = array(
'title' => $link_title,
'url' => htmlspecialchars_decode($link_url),
'type' => $link_type,
'permission' => $link_permissions,
);
add_log('admin', 'LOG_PORTAL_LINK_UPDATED', $link_title);
}
else
{
$message = $user->lang['LINK_ADDED'];
$links[] = array(
'title' => $link_title,
'url' => htmlspecialchars_decode($link_url),
'type' => $link_type,
'permission' => $link_permissions,
);
add_log('admin', 'LOG_PORTAL_LINK_ADDED', $link_title);
}
$board3_links_array = serialize($links);
set_portal_config('board3_links_array_' . $module_id, $board3_links_array);
trigger_error($message . adm_back_link($u_action));
break;
// Delete link
case 'delete':
if (!isset($link_id) && $link_id >= sizeof($links))
{
trigger_error($user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING);
}
if (confirm_box(true))
{
$cur_link_title = $links[$link_id]['title'];
// delete the selected link and reset the array numbering afterwards
array_splice($links, $link_id, 1);
$links = array_merge($links);
$board3_links_array = serialize($links);
set_portal_config('board3_links_array_' . $module_id, $board3_links_array);
add_log('admin', 'LOG_PORTAL_LINK_REMOVED', $cur_link_title);
}
else
{
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
'link_id' => $link_id,
'action' => 'delete',
)));
}
break;
// Move items up or down
case 'move_up':
case 'move_down':
if (!isset($link_id) && $link_id >= sizeof($links))
{
trigger_error($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
if (($link_id == 0 && $action == 'move_up') || ($link_id == (sizeof($links) - 1) && $action == 'move_down'))
{
break;
}
/*
* on move_down, switch position with next order_id...
* on move_up, switch position with previous order_id...
* move up means a lower ID, move down means a higher ID
*/
$switch_order_id = ($action == 'move_down') ? $link_id + 1 : $link_id - 1;
// back up the info of the link we want to move
$cur_link = array(
'title' => $links[$link_id]['title'],
'url' => $links[$link_id]['url'],
'type' => $links[$link_id]['type'],
'permission' => $links[$link_id]['permission'],
);
// move the info of the links we replace in the order
$links[$link_id] = array(
'title' => $links[$switch_order_id]['title'],
'url' => $links[$switch_order_id]['url'],
'type' => $links[$switch_order_id]['type'],
'permission' => $links[$switch_order_id]['permission'],
);
// insert the info of the moved link
$links[$switch_order_id] = $cur_link;
$board3_links_array = serialize($links);
set_portal_config('board3_links_array_' . $module_id, $board3_links_array);
break;
// Edit or add menu item
case 'edit':
case 'add':
$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']) : '',
//'U_BACK' => $u_action,
'U_ACTION' => $u_action . '&amp;id=' . $link_id,
'S_EDIT' => true,
'S_LINK_IS_INT' => (isset($links[$link_id]['type']) && $links[$link_id]['type'] == B3_LINKS_INT) ? true : false,
));
$groups_ary = (isset($links[$link_id]['permission'])) ? explode(',', $links[$link_id]['permission']) : array();
// get group info from database and assign the block vars
$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))
{
$template->assign_block_vars('permission_setting', 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_ID' => $row['group_id'],
));
}
$db->sql_freeresult($result);
return;
break;
}
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']) : '',
'LINK_URL' => ($action != 'add') ? str_replace('&', '&amp;', $links[$i]['url']) : '',
'U_EDIT' => $u_action . '&amp;action=edit&amp;id=' . $i,
'U_DELETE' => $u_action . '&amp;action=delete&amp;id=' . $i,
'U_MOVE_UP' => $u_action . '&amp;action=move_up&amp;id=' . $i,
'U_MOVE_DOWN' => $u_action . '&amp;action=move_down&amp;id=' . $i,
));
}
}
function update_links($key, $module_id)
{
$this->manage_links('', $key, $module_id);
}
// Unserialize links array
function utf_unserialize($serial_str)
{
$out = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $serial_str );
return unserialize($out);
}
}
?>

View File

@@ -107,13 +107,13 @@ class portal_main_menu_module
}
}
return 'main_menu_new.html';
return 'main_menu_side.html';
}
function get_template_acp($module_id)
{
// do not remove this as it is needed in order to run manage_links
return array(
return array(
'title' => 'ACP_PORTAL_MENU',
'vars' => array(
'legend1' => 'ACP_PORTAL_MENU',
@@ -243,11 +243,6 @@ class portal_main_menu_module
$link_id = request_var('id', 99999999); // 0 will trigger unwanted behavior, therefore we set a number we should never reach
$portal_config = obtain_portal_config();
$sql = 'SELECT module_id FROM ' . PORTAL_MODULES_TABLE . " WHERE module_classname = 'main_menu'";
$result = $db->sql_query($sql);
$module_id = $db->sql_fetchfield('module_id');
$db->sql_freeresult($result);
$links = array();
$links = $this->utf_unserialize($portal_config['board3_menu_array_' . $module_id]);

View File

@@ -0,0 +1,12 @@
<!--version $Id: main_menu_new.html 697 2010-09-13 23:11:16Z marc1706 $ //-->
{$LR_BLOCK_H_L}<!-- IF $S_BLOCK_ICON --><img src="{T_THEME_PATH}/images/portal/portal_menu.png" width="16" height="16" alt="" />&nbsp;<!-- ENDIF -->{L_PORTAL_LINKS}{$LR_BLOCK_H_R}
<div class="portal-navigation">
<ul>
<!-- BEGIN portallinks -->
<li><a href="{portallinks.LINK_URL}" title="{portallinks.LINK_TITLE}">{portallinks.LINK_TITLE}</a></li>
<!-- BEGINELSE -->
<span style="float:left;" class="gensmall"><strong>{L_LINKS_NO_LINKS}</strong></span><br />
<!-- END portallinks -->
</ul>
</div>
{$LR_BLOCK_F_L}{$LR_BLOCK_F_R}

View File

@@ -1,14 +0,0 @@
<!--version $Id$ //-->
{$LR_BLOCK_H_L}<!-- IF $S_BLOCK_ICON --><img src="{T_THEME_PATH}/images/portal/portal_menu.png" width="16" height="16" alt="" />&nbsp;<!-- ENDIF -->{L_M_MENU}{$LR_BLOCK_H_R}
<div class="portal-navigation">
<!-- BEGIN portalmenu -->
<div class="menutitle">{portalmenu.CAT_TITLE}</div>
<ul>
<!-- BEGIN links -->
<li><a href="{portal_menu.links.LINK_URL}">{portalmenu.links.LINK_TITLE}</a></li>
<!-- END links -->
</ul>
<hr class="dashed" />
<!-- END portal_menu -->
</div>
{$LR_BLOCK_F_L}{$LR_BLOCK_F_R}

View File

@@ -1,29 +1,18 @@
<!--version $Id$ //-->
{$LR_BLOCK_H_L}<!-- IF $S_BLOCK_ICON --><img src="{T_THEME_PATH}/images/portal/portal_menu.png" width="16" height="16" alt="" />&nbsp;<!-- ENDIF -->{L_M_MENU}{$LR_BLOCK_H_R}
<div class="portal-navigation">
<div class="menutitle">{L_M_CONTENT}</div>
<!-- BEGIN portalmenu -->
<div class="menutitle">{portalmenu.CAT_TITLE}</div>
<ul>
<li><a href="{U_INDEX}">{L_INDEX}</a></li>
<!-- IF S_DISPLAY_SEARCH -->
<li><a href="{U_SEARCH}">{L_SEARCH}</a></li>
<!-- ENDIF -->
<!-- IF not S_USER_LOGGED_IN and S_REGISTER_ENABLED -->
<li><a href="{U_REGISTER}">{L_REGISTER}</a></li>
<!-- ENDIF -->
<!-- IF not S_IS_BOT and S_DISPLAY_MEMBERLIST -->
<li><a href="{U_MEMBERLIST}">{L_MEMBERLIST}</a></li>
<!-- ENDIF -->
<!-- IF U_TEAM -->
<li><a href="{U_TEAM}">{L_THE_TEAM}</a></li>
<!-- ENDIF -->
<!-- BEGIN links -->
<li><a href="{portal_menu.links.LINK_URL}">{portalmenu.links.LINK_TITLE}</a></li>
<!-- END links -->
</ul>
<hr class="dashed" />
<div class="menutitle">{L_M_HELP}</div>
<ul>
<li><a href="{U_FAQ}">{L_FAQ}</a></li>
<li><a href="{U_M_BBCODE}">{L_M_BBCODE}</a></li>
<li><a href="{U_M_TERMS}">{L_M_TERMS}</a></li>
<li><a href="{U_M_PRV}">{L_M_PRV}</a></li>
</ul>
<!-- BEGINELSE -->
<ul>
<span style="float:left;" class="gensmall"><strong>{L_MENU_NO_LINKS}</strong></span><br />
</ul>
<!-- END portal_menu -->
</div>
{$LR_BLOCK_F_L}{$LR_BLOCK_F_R}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB