Skip to content

Instantly share code, notes, and snippets.

@prototech
Created February 14, 2014 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prototech/8995465 to your computer and use it in GitHub Desktop.
Save prototech/8995465 to your computer and use it in GitHub Desktop.
<?php
/**
*
* @package phpBB3
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
*/
/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
$user_cnt = $request->variable('users', 5);
$user->lang = array_merge($user->lang, array(
// This applies for NOTIFICATION_BOOKMARK, NOTIFICATION_POST, and NOTIFICATION_QUOTE.
// %1$s will return a list of users that's concatenated using "," and "and" - see STRING_LIST
// Once the user count reaches 5 users or more, the list is trimmed using NOTIFICATION_X_OTHERS
// Examples:
// A replied...
// A and B replied...
// A, B and C replied...
// A, B, C and 2 others replied...
'NOTIFICATION_BOOKMARK' => array(
1 => '%1$s replied to the topic “%2$s” you have bookmarked.',
),
'NOTIFICATION_POST' => array(
1 => '%1$s replied to the topic “%2$s”.',
),
'NOTIFICATION_QUOTE' => array(
1 => '%1$s quoted you in the post “%2$s”.',
),
// Used in conjuction with NOTIFICATION_BOOKMARK, NOTIFICATION_POST, and NOTIFICATION_QUOTE.
'NOTIFICATION_X_OTHERS' => array(
2 => '%d others',
),
'STRING_LIST' => array(
1 => '%1$s',
2 => '%1$s and %2$s',
// At 3 or more, %1$s returns comma separated items. So output would be: X, Y and Z
),
));
$output = '';
$users = array('A', 'B', 'C', 'D');
for ($i = 1; $i <= $user_cnt; $i++)
{
$responders = array_slice($users, 0, $i);
if ($i > 4)
{
array_splice($responders, 3);
}
$trimmed_responders_cnt = $i - sizeof($responders);
if ($trimmed_responders_cnt)
{
$responders[] = $user->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt);
}
$user_list = phpbb_gen_string_list($responders, $user);
$output .= $user->lang('NOTIFICATION_BOOKMARK', $user_list, 'Testing', $i) . '<br />';
$output .= $user->lang('NOTIFICATION_POST', $user_list, 'Testing', $i) . '<br />';
$output .= $user->lang('NOTIFICATION_QUOTE', $user_list, 'Testing', $i) . '<br /><br />';
}
trigger_error($output);
/**
* Concatenate an array into a string list.
*
* @param array $items Array of items to concatenate
* @param object $user The phpBB $user object.
*
* @return string String list. Examples: "A"; "A and B"; "A, B and C"
*/
function phpbb_gen_string_list($items, $user)
{
$count = sizeof($items);
$last_item = '';
if ($count > 1)
{
$last_item = array_pop($items);
}
$list = implode($user->lang['COMMA_SEPARATOR'], $items);
return $user->lang('STRING_LIST', $list, $last_item, $count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment