Advertisement:

Author Topic: Modbreak tag  (Read 49152 times)

Offline Aaron

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,711
  • Gender: Male
    • Aaronweb.net
Re: Modbreak tag
« Reply #60 on: February 20, 2009, 04:42:17 AM »
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. ;)

Offline PerryM

  • Jr. Member
  • **
  • Posts: 111
Re: Modbreak tag
« Reply #61 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.
Perry

Propaganistas

  • Guest
Re: Modbreak tag
« Reply #62 on: March 01, 2009, 09:12:52 AM »
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

Offline Pandabeer

  • Newbie
  • *
  • Posts: 4
Re: Modbreak tag
« Reply #63 on: April 27, 2009, 07:31:10 AM »
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>';
}
« Last Edit: April 27, 2009, 08:03:34 AM by Pandabeer »

Offline TheDeath

  • Semi-Newbie
  • *
  • Posts: 26
Re: Modbreak tag
« Reply #64 on: May 15, 2009, 07:58:06 AM »
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:
Code: [Select]
// 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:
Code: [Select]

// ######## 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:
Code: [Select]
$txt['unformat_text'] = 'Remove Formatting';

add after:
Code: [Select]
$txt['modbreak'] = 'Moderator Break';

./Themes/default/languages/Post.german-utf8.php
search:
Code: [Select]
$txt['unformat_text'] = 'Formatierung entfernen';

add after:
Code: [Select]
$txt['modbreak'] = 'Moderator Kommentar';


Sorry for my bad english. ;)

Offline Cal O'Shaw

  • Full Member
  • ***
  • Posts: 444
  • SMF 1.1.14 & 2.0 Sites
Re: Modbreak tag
« Reply #65 on: May 16, 2009, 02:19:38 AM »
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)

Offline TheDeath

  • Semi-Newbie
  • *
  • Posts: 26
Re: Modbreak tag
« Reply #66 on: May 16, 2009, 08:27:54 AM »
HI Cal,

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

./Themes/default/Post.template.php
search:
Code: [Select]
'list' => array('code' => 'list', 'before' => '[list]\n[li]', 'after' => '[/li]\n[li][/li]\n[/list]', 'description' => $txt[261]),
);

add after:
Code: [Select]

// ######## 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']);
}
// #######################################################################################################################################

Offline Cal O'Shaw

  • Full Member
  • ***
  • Posts: 444
  • SMF 1.1.14 & 2.0 Sites
Re: Modbreak tag
« Reply #67 on: May 17, 2009, 12:56:21 AM »
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

Offline Cal O'Shaw

  • Full Member
  • ***
  • Posts: 444
  • SMF 1.1.14 & 2.0 Sites
Re: Modbreak tag
« Reply #68 on: May 17, 2009, 02:12:09 AM »
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
« Last Edit: May 18, 2009, 04:02:46 AM by Cal O'Shaw »

Offline TheDeath

  • Semi-Newbie
  • *
  • Posts: 26
Re: Modbreak tag
« Reply #69 on: May 17, 2009, 09:25:57 AM »
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:
Code: [Select]

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>';


Offline Cal O'Shaw

  • Full Member
  • ***
  • Posts: 444
  • SMF 1.1.14 & 2.0 Sites
Re: Modbreak tag
« Reply #70 on: May 18, 2009, 04:00:32 AM »
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

Offline TheDeath

  • Semi-Newbie
  • *
  • Posts: 26
Re: Modbreak tag
« Reply #71 on: May 18, 2009, 04:59:08 AM »
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.

Offline Mr. Jinx

  • Full Member
  • ***
  • Posts: 475
  • Gender: Male
    • Ziggo Forum Chelloo
Re: Modbreak tag
« Reply #72 on: May 23, 2009, 08:19:40 AM »
@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]);
}
}

Offline Cal O'Shaw

  • Full Member
  • ***
  • Posts: 444
  • SMF 1.1.14 & 2.0 Sites
Re: Modbreak tag
« Reply #73 on: May 24, 2009, 05:58:35 PM »
@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

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 73,189
Re: Modbreak tag
« Reply #74 on: June 02, 2009, 10:49:45 AM »
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

Offline coldy316

  • Jr. Member
  • **
  • Posts: 164
  • Gender: Male
  • G'day mate, how ya doin
Re: Modbreak tag
« Reply #75 on: June 08, 2009, 01:57:33 PM »
I understand all that but where in the style.css do you add the code
this part
Code: [Select]
.modbreak
{
border: 1px solid #000000;
}

.modbreak legend
{
color: #DD0000;
font-weight: bold;
}
Would you believe it that i live in gods country
Australia

Offline Mr. Jinx

  • Full Member
  • ***
  • Posts: 475
  • Gender: Male
    • Ziggo Forum Chelloo
Re: Modbreak tag
« Reply #76 on: June 12, 2009, 12:06:59 PM »
Code: (replace with) [Select]
$parts[$i] = preg_replace('~\##/]?modbreak(=[^\]]*)?\]~i', '', $parts[$i]);

Thanks Arantor!

Offline Blinker

  • Full Member
  • ***
  • Posts: 472
  • Gender: Male
Re: Modbreak tag
« Reply #77 on: July 05, 2009, 06:57:29 AM »
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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 73,189
Re: Modbreak tag
« Reply #78 on: July 05, 2009, 06:58:56 AM »
Blinker - the modifications I mention above do just that.
No good deed goes unpunished
All helpful urges should be circumvented

Offline Blinker

  • Full Member
  • ***
  • Posts: 472
  • Gender: Male
Re: Modbreak tag
« Reply #79 on: July 05, 2009, 07:11:28 AM »
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.