Hide tag

Alex Kur

Пользователь
#1
Данная модификация добавляет тег hide с парочкой параметров для выборочного сокрытия контента.
Пример использования:

[hide rank="администратор" users="alexxkur, admin"] Лалала [/hide]
Доступные параметры:
1. rank - хайд по рангу пользователя ( user_rank ). Свойство "logged in" предоставляет доступ только пользователям. Доступен множественный выбор (кроме logged in).
2. users - фильтр по нику пользователя. Доступен множественный выбор.
3. points - фильтр по сид бонусу.
4. language - мой любимый, дискредитирующий параметр. Ставит хайд на язык пользователя:

[hide language="ua"]Хутин - Пуйло, ла-ла-ла-ла-ла-ла[/hide]
[hide language="ru" rank="logged in"]Путин наш президент![/hide]
[hide language="en"]Putin - DickHead[/hide]
Installation:

OPEN



FIND


if (count($orig_word))
{
if ($user_sig)
{
$user_sig = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $user_sig . '<'), 1, -1));
}

$message = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $message . '<'), 1, -1));
}
AFTER ADD

// Hiding information by options

preg_match_all('/\[hide(.+)\](.+)\[\/hide\]/Ui', $message, $hide_arr);

foreach( $hide_arr[0] as $key => $value )
{

$access_error = array();
$error_msg = NULL;
$silent = FALSE;

preg_match_all('/\s(.+)=["\'](.+)["\']/Ui', $value, $options_array);

foreach( $options_array[1] as $key2 => $value2 )
{

$option = $options_array[2][$key2];

switch( $value2 )
{
case 'rank':

$rank_allowed = $option;
$option = mb_strtolower( str_replace(' ' , '', $option) );

$option = explode(',', $option );

if( $rank_allowed == 'logged in' AND $userdata['user_id'] == DELETED ) $access_error[] = ' be ' . $rank_allowed;
elseif( !in_array( $ranks[$userdata['user_rank']]['rank_title'], $option ) ) $access_error[] = ' be ' . $rank_allowed;


break;

case 'users' :

$user_allowed = $option;
$option = str_replace(' ' , '', $option);

$option = explode(',', $option );

if( !in_array( $userdata['username'], $option ) ) $access_error[] = ' be ' . $user_allowed;

break;

case 'points' :

if( $userdata['user_points'] < $option ) $access_error[] = ' have ' . $option . ' seed points';

break;

case 'language':

if( $userdata['user_lang'] != $option )
$silent = TRUE; // Not to show error message if deny

break;

}
}

if( $userdata['user_level'] == 1 or $poster == $userdata['username'] ) $access_error = NULL;

if( $silent ) $message = str_replace( $value , NULL , $message);
if( !empty( $access_error ) )
{
foreach( $access_error as $num => $msg )
{
if( $num == 0 ) $error_msg = "<span>$msg</span>";
else $error_msg .= ", <span>$msg</span>";
}

$message = str_replace( $value , '<span style="background: rgb(209, 5, 5); padding: 5px; color: white;">To see this block you must: ' . $error_msg . '</span>', $message);
}
else $message = str_replace( $hide_arr[0][$key] ,$hide_arr[2][$key], $message);

}
OPEN

FIND

foreach ($unsorted_rows as $row)
{
$tmp[$row['post_id']] = $row;

AFTER ADD

preg_match_all('/\[hide(.+)\](.+)\[\/hide\]/Ui', $tmp[$row['post_id']]['post_html'], $hide_arr);

$ranks = $datastore->get('ranks');

foreach( $hide_arr[0] as $key => $value )
{

$access_error = array();
$error_msg = NULL;
$silent = FALSE;

preg_match_all('/\s(.+)=["\'](.+)["\']/Ui', $value, $options_array);

foreach( $options_array[1] as $key2 => $value2 )
{

$option = $options_array[2][$key2];

switch( $value2 )
{
case 'rank':

$rank_allowed = $option;
$option = mb_strtolower( str_replace(' ' , '', $option) );

$option = explode(',', $option );

if( $rank_allowed == 'logged in' AND $userdata['user_id'] == DELETED) $access_error[] = ' be ' . $rank_allowed;
elseif( !in_array( $ranks[$userdata['user_rank']]['rank_title'], $option ) ) $access_error[] = ' be ' . $rank_allowed;


break;

case 'users' :

$user_allowed = $option;
$option = str_replace(' ' , '', $option);

$option = explode(',', $option );

if( !in_array( $userdata['username'], $option ) ) $access_error[] = ' be ' . $user_allowed;

break;

case 'points' :

if( $userdata['user_points'] < $option ) $access_error[] = ' have ' . $option . ' seed points';

break;

case 'language':

if( $userdata['user_lang'] != $option )
$silent = TRUE; // Not to show error message if deny

break;

}
}

if( $userdata['user_level'] == 1 or $poster == $userdata['username'] ) $access_error = NULL;

if( $silent ) $tmp[$row['post_id']]['post_html'] = str_replace( $value , NULL , $tmp[$row['post_id']]['post_html']);
if( !empty( $access_error ) )
{
foreach( $access_error as $num => $msg )
{
if( $num == 0 ) $error_msg = "<span>$msg</span>";
else $error_msg .= ", <span>$msg</span>";
}

$tmp[$row['post_id']]['post_html'] = str_replace( $value , '<span style="background: rgb(209, 5, 5); padding: 5px; color: white;">To see this block you must: ' . $error_msg . '</span>', $tmp[$row['post_id']]['post_html']);
}
else $tmp[$row['post_id']]['post_html'] = str_replace( $hide_arr[0][$key] ,$hide_arr[2][$key], $tmp[$row['post_id']]['post_html']);

}
 
Сверху