• Welcome to Simple Machines Community Forum. Please login or sign up.

Modbreak tag

Started by Aaron, January 10, 2007, 12:43:06 PM

Previous topic - Next topic

Aaron

Quote from: d0brin on February 19, 2009, 03:30:36 PM
Can this mode be update for smf 1.1.8 pls :)

It doesn't need to be updated. It'll work just fine on SMF 1.1.8. ;)

PerryM

Nice feature but can it be called something besides [modbreak]

How about [Moderator Comment]

My users and I speak English and Geek Speak is something we try to avoid.
Perry

Propaganistas

Quote from: PerryM on February 20, 2009, 01:28:05 PM
Nice feature but can it be called something besides [modbreak]

How about [Moderator Comment]

My users and I speak English and Geek Speak is something we try to avoid.

Sure,
to install it using your tag, unzip and open install.xml, or if you have it already installed open Sources/Subs.php:

Code (find) Select
$legend = 'modbreak';
Code (replace) Select
$legend = 'Moderator Comment';

Execute this twice, as there are two of these pieces:
Code (find) Select
'tag' => 'modbreak',
Code (replace) Select
'tag' => 'Moderator Comment',

Additionally, if you want it to be only used by Moderators, take a look at this post. This actually erases the tag when a non-moderator tries to edit his/her post.  It only works for the normal tag (without equation mark) though.

Greetz

Pandabeer

April 27, 2009, 07:31:10 AM #63 Last Edit: April 27, 2009, 08:03:34 AM by Pandabeer
nvm i made this:

// Modbreak function
function get_modbreak($content$name null)
{
	
global 
$txt$settings$context$modSettings;

	
$legend 'Modbreak by ' $name;

    if(empty(
$name))
	
	
return 
'Im a noob because i fake a modbreak =)';

	
return 
'
	
<fieldset class="modbreak"><legend>' 
$legend '</legend>' $content '</fieldset>';
}

TheDeath

Hello all.

1: Thank Aäron for this great mod.
I have this installed on SMF2.0 RC1 and the moderator's of the board are very happy ;).

2: Many people have question about BBC-Button.
The code at the end, add the BBC-Button in SMF2.0 RC1.
All user with permission "moderate_board" can see the button.

3: You must create a new BBC-Button Image,  and copy it to your
./Themes/default/images/bbc   directory.
The name of button image must be "modbreak.gif".
I have rename another bbc button for test.

4: Maybe someone can create a new button and post it in thread, thanks.


$sourcedir/Subs-Editor.php 
search:

// Show the toggle?
if (empty($modSettings['disable_wysiwyg']))
{
$context['bbc_tags'][1][] = array();
$context['bbc_tags'][1]['unformat'] = array('code' => 'unformat', 'before' => '', 'description' => $txt['unformat_text']);
$context['bbc_tags'][1]['toggle'] = array('code' => 'toggle', 'before' => '', 'description' => $txt['toggle_view']);
}


add after:

// ######## BBC Button for MODBREAK ######################################################################################################
if (allowedTo('moderate_board'))
{
$context['bbc_tags'][1][] = array();
$context['bbc_tags'][1]['modbreak'] = array('code' => 'modbreak', 'before' => '[modbreak]', 'after' => '[/modbreak]', 'description' => $txt['modbreak']);
}
// #######################################################################################################################################




./Themes/default/languages/post.english.php
search:

$txt['unformat_text'] = 'Remove Formatting';


add after:

$txt['modbreak'] = 'Moderator Break';


./Themes/default/languages/Post.german-utf8.php
search:

$txt['unformat_text'] = 'Formatierung entfernen';


add after:

$txt['modbreak'] = 'Moderator Kommentar';




Sorry for my bad english. ;)

Cal O'Shaw

How could that 'moderate_board" conditional be added to the 1.1.x code?

The bloody PERMISSIONS MOD keeps breaking other mods that utilise permissions and the only reason I installed the blasted PERMISSIONS MOD is to protect MODBREAK from abuse.  If this "moderate_board" check could be implemented I could get rid of PERMISSIONS MOD and not get frantic emails that all the formatting tags are disabled (because PERMISSIONS felt like it).

Grazie,

Cal (using 1.1.8)

TheDeath

HI Cal,

you can it make so. I have testet with SMF 1.1.8.

./Themes/default/Post.template.php
search:

'list' => array('code' => 'list', 'before' => '[list]\n[li]', 'after' => '[/li]\n[li][/li]\n[/list]', 'description' => $txt[261]),
);


add after:

// ######## BBC Button for MODBREAK ######################################################################################################
if (allowedTo('moderate_board'))
{
$context['bbc_tags'][1][] = array();
$context['bbc_tags'][1]['modbreak'] = array('code' => 'modbreak', 'before' => '[modbreak]', 'after' => '[/modbreak]', 'description' => $txt['modbreak']);
}
// #######################################################################################################################################

Cal O'Shaw

Hello,

I'm sorry, I didn't make clear what I needed to do.

Your fix certainly does take care of not displaying a MODBREAK BBC icon unless one is authorised to moderate that board.

Unfortunately, someone NOT a moderator can type the characters "[modbreak]I am not authorised but here is a MODBREAK BOX anyway![/modbreak]" and create the MODBREAK anyway.


But perhaps the allowedTo logic can be used where the MODBREAK BBC tag gets processed?


In the meantime it looks like the PERMISSION MOD continues to be used... foo...

Cal

Cal O'Shaw

May 17, 2009, 02:12:09 AM #68 Last Edit: May 18, 2009, 04:02:46 AM by Cal O'Shaw
And now I turn around and say grazie mille TheDeath!

I took the allowedTo logic and made an absurdly simple fix to limit MODBREAK making boxes only where the author is allowed to do it.  And where they can't, such as moderators trying to do it in a board they don't moderate, it resolves to an error message.

This is in Sources/Subs.php

Code (locate) Select
// Modbreak function
function get_modbreak($content, $legend = null)
{
global $txt, $settings, $context, $modSettings;

if (empty($legend))
$legend = 'Modbreak';



Code ( add after) Select
if (allowedTo('moderate_board'))


Code (locate) Select
return '
<fieldset class="modbreak"><legend>' . $legend . '</legend>' . $content . '</fieldset>';


Code (add after) Select
else return '<span style="color: red;">Sorry, you are not authorised to use MODBREAK here.</span>
';



I'm pretty sure this is solid, after testing with users, moderators, and global moderators, but if anyone wants to double-check.

Aaron, if this meets with your approval, would you consider integrating it formally into MODBREAK?  (This didn't work right... it hides MODBREAKs from regular members)

Many thanks to Aaron for creating MODBREAK and TheDeath for giving me the pieces to find a fix.

Now I can get rid of PERMISSIONS MOD!!!

Cal

TheDeath

Hi Cal,

then I use your change, the user that can't moderate board see "Sorry, you are not authorised to use MODBREAK here" and not the Modbreak that have a moderator wrote.


About your code, you can it write so:


if (empty($legend))
$legend = 'Moderator Comment';

if (!allowedTo('moderate_board'))
return '<span style="color: red;">Sorry, you are not authorised to use MODBREAK here.</span>';

return '<fieldset class="modbreak"><legend>' . $legend . '</legend>' . $content . '</fieldset>';


Cal O'Shaw

This is what I get for not testing every permutation.  Regular members can't see the MODBREAK.

There is clearly a way to prevent posters from using the modbreak tag.  I suspect that if the allowedTo test can be performed where the modbreak tag is defined into 2 arrays, then I can stop regular members from using it.

Here is the MODBREAK BBC definition code in the Subs.php file:
Code (MODBREAK BBC definition arrays) Select
array(
'tag' => 'modbreak',
'type' => 'unparsed_content',
'content' => '$1',
'block_level' => true,
'validate' => create_function('&$tag, &$data, $disabled', '$data = get_modbreak(parse_bbc($data, ' . ($smileys ? 'true' : 'false') . ',\'' . $cache_id . '\'));'),
),
array(
'tag' => 'modbreak',
'type' => 'unparsed_equals_content',
'content' => '$1',
'block_level' => true,
'validate' => create_function('&$tag, &$data, $disabled', '$data[0] = get_modbreak(parse_bbc($data[0], ' . ($smileys ? 'true' : 'false') . ',\'' . $cache_id . '\'), $data[1]);'),
),


I don't know PHP well enough to edit the array entries to add the allowedTo logic. 

However, it seems the place to use the allowedTo is on the 'validate' line in the create_function.  But just adding 'if (!allowedTo('moderate_board'))' before '$date[0]=' or after it breaks the code, so I know there is a bit more (global allowedTo()?).

Does that make sense?  Will this stop people trying to create posts from using MODBREAK but still allow everyone to see the MODBREAK?

I do appreciate all the time you are spending on this.

Grazie,

Cal

TheDeath

Hello Cal,

in the File "./Sources/Subs-Post.php" is a function with name
function preparsecode(&$message$previewing false)
The function Parses some bbc before sending into the database.

A other good position is in "./Sources/Post.php".

Search for:
	
// Check the subject and message.
	
if (!isset(
$_POST['subject']) || $func['htmltrim']($_POST['subject']) === '')
	
	
$post_errors[] = 'no_subject';
	
if (!isset(
$_POST['message']) || $func['htmltrim']($_POST['message']) === '')
	
	
$post_errors[] = 'no_message';
	
elseif (!empty(
$modSettings['max_messageLength']) && $func['strlen']($_POST['message']) > $modSettings['max_messageLength'])
	
	
$post_errors[] = 'long_message';
	
else
	
{
	
	
// Prepare the message a bit for some additional testing.
	
	
$_POST['message'] = $func['htmlspecialchars']($_POST['message'], ENT_QUOTES);

	
	
// Preparse code. (Zef)
	
	
if (
$user_info['is_guest'])
	
	
	
$user_info['name'] = $_POST['guestname'];
	
	
preparsecode($_POST['message']);    // <-- her is the function, that check BBC-Code !!!!

	
	
// Let's see if there's still some content left without the tags.
	
	
if (
$func['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), '<img>')) === '')
	
	
	
$post_errors[] = 'no_message';
	
}


How can parse messagetext for modbreak an can generate a errormessage.

When I have time, I show how can eliminate modbreak tag for regular members.

Mr. Jinx

@Cal O'Shaw:
Did you take a look at this mod?
http://www.simplemachines.org/community/index.php?topic=293440.0
Works for me, allowing only moderators to use the modbreak tag.

Sources/Subs-Post.php

Code (find) Select

if (!$previewing && strpos($parts[$i], '[html]') !== false)
{
if (allowedTo('admin_forum'))
$parts[$i] = preg_replace('~\[html\](.+?)\[/html\]~ise', '\'[html]\' . strtr(un_htmlspecialchars(\'$1\'), array("\n" => \'&#13;\', \'  \' => \' &#32;\')) . \'[/html]\'', $parts[$i]);
// We should edit them out, or else if an admin edits the message they will get shown...
else
{
while (strpos($parts[$i], '[html]') !== false)
$parts[$i] = preg_replace('~\[[/]?html\]~i', '', $parts[$i]);
}
}




Code (replace with) Select

if (!$previewing && strpos($parts[$i], '[html]') !== false)
{
if (allowedTo('admin_forum'))
$parts[$i] = preg_replace('~\[html\](.+?)\[/html\]~ise', '\'[html]\' . strtr(un_htmlspecialchars(\'$1\'), array("\n" => \'&#13;\', \'  \' => \' &#32;\')) . \'[/html]\'', $parts[$i]);
// We should edit them out, or else if an admin edits the message they will get shown...
else
{
while (strpos($parts[$i], '[html]') !== false)
$parts[$i] = preg_replace('~\[[/]?html\]~i', '', $parts[$i]);
}
}

    if (!$previewing && strpos($parts[$i], '[modbreak]') !== false)
{
if (allowedTo('moderate_board'))
$parts[$i] = preg_replace('~\[modbreak\](.+?)\[/modbreak\]~ise', '\'[modbreak]\' . strtr(un_htmlspecialchars(\'$1\'), array("\n" => \'&#13;\', \'  \' => \' &#32;\')) . \'[/modbreak]\'', $parts[$i]);
// We should edit them out, or else if an admin edits the message they will get shown...
else
{
while (strpos($parts[$i], '[modbreak]') !== false)
$parts[$i] = preg_replace('~\[[/]?modbreak\]~i', '', $parts[$i]);
}
}


Cal O'Shaw

@Mr. Jinx,

That did the trick!  Grazie!

So, now...

Aaron, would you consider adding the code to modify Subs-post.php as given in Reply #72 above?  It would be greatly appreciated.

Cal

Arantor

The above code in Reply #72 is good but it doesn't have the additional ability to filter out [modbreak=title] comments.

Code (remove) Select

while (strpos($parts[$i], '[modbreak]') !== false)
$parts[$i] = preg_replace('~\##/]?modbreak\]~i', '', $parts[$i]);


Code (replace with) Select

$parts[$i] = preg_replace('~\##/]?modbreak(=[^\]]*)?\]~i', '', $parts[$i]);


Note: the two # symbols should be replaced with [ symbols - the wiki links mod prevented me from posting otherwise.
No good deed goes unpunished
All helpful urges should be circumvented

coldy316

I understand all that but where in the style.css do you add the code
this part

.modbreak
{
border: 1px solid #000000;
}

.modbreak legend
{
color: #DD0000;
font-weight: bold;
}

Would you believe it that i live in gods country
Australia

Mr. Jinx

Quote from: Arantor on June 02, 2009, 10:49:45 AM
Code (replace with) Select

$parts[$i] = preg_replace('~\##/]?modbreak(=[^\]]*)?\]~i', '', $parts[$i]);


Thanks Arantor!

Blinker

I was looking for a way to restrict non admins or mods using the modbreak tag (I haven't bothered with a button yet). I read through a bunch of posts and thought "there must be an easier way".

Did anyone try this mod - http://custom.simplemachines.org/mods/index.php?mod=449 ? It installed just fine on 1.1.9 (although it says 1.1.2). I simply unticked modbreak from the list of BBCode in the permissions for my main membergroups and that was it. Simple.

Forgive me if this has been discussed already, I didn't notice it.

Arantor

Blinker - the modifications I mention above do just that.
No good deed goes unpunished
All helpful urges should be circumvented

Blinker

Was that the subs-post edits? Cool.

The BBC Permissions mod also works for [modbreak=Custom Title] instances and I guess the added benefit is I can use it for any future custom BBC I choose to add.

Quick question Arantor - does the subs-post edit option simply show the unparsed code or does it stop the user with an error message? Stopping them entirely would be preferable so let me know and I may switch to that hack instead.

Advertisement: