News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Custom Permission Code Help

Started by Iomega0318, April 08, 2012, 06:06:11 PM

Previous topic - Next topic

Iomega0318

Ok I redid the post and made all the code a LOT shorter, my php file is also uploaded if you need to look at all the coding.
What I need is help adding a custom permission to Subs-Editor.php the permission will basically allow admins to see it but not anyone else, the code I need "blocked" is highlighted in red below:

Quote if (empty($context['bbc_tags']))
{
// The below array makes it dead easy to add images to this control. Add it to the array and everything else is done for you!
$context['bbc_tags'] = array();
$context['bbc_tags'][] = array(
array(
'image' => 'bold',
'code' => 'b',
'before' => '[b]',
'after' => '[/b]',
'description' => $txt['bold'],
),
array(
'image' => 'italicize',
'code' => 'i',
'before' => '[i]',
'after' => '[/i]',
'description' => $txt['italic'],
),
array(
'image' => 'underline',
'code' => 'u',
'before' => '[u]',
'after' => '[/u]',
'description' => $txt['underline']
),
array(
'image' => 'strike',
'code' => 's',
'before' => '[s]',
'after' => '[/s]',
'description' => $txt['strike']
),
array(),
array(
'image' => 'pre',
'code' => 'pre',
'before' => '[pre]',
'after' => '[/pre]',
'description' => $txt['preformatted']
),
array(
'image' => 'left',
'code' => 'left',
'before' => '[left]',
'after' => '[/left]',
'description' => $txt['left_align']
),
array(
'image' => 'center',
'code' => 'center',
'before' => '[center]',
'after' => '[/center]',
'description' => $txt['center']
),
array(
'image' => 'right',
'code' => 'right',
'before' => '[right]',
'after' => '[/right]',
'description' => $txt['right_align']
),
);
$context['bbc_tags'][] = array(
array(
'image' => 'flash',
'code' => 'flash',
'before' => '[flash=200,200]http://',
'after' => '[/flash]',
'description' => $txt['flash']
),
array(
'image' => 'img',
'code' => 'img',
'before' => '[img]http://',
'after' => '[/img]',
'description' => $txt['image']
),
array(
'image' => 'url',
'code' => 'url',
'before' => '[url=http://',
'after' => ']',
'after' => '[/url]',
'description' => $txt['hyperlink']
),
array(
'image' => 'email',
'code' => 'email',
'before' => '[email]',
'after' => '[/email]',
'description' => $txt['insert_email']
),
array(
'image' => 'ftp',
'code' => 'ftp',
'before' => '[ftp=ftp://',
'after' => ']',
'after' => '[/ftp]',
'description' => $txt['ftp']
),
         array(),
         array(
         'image' => 'error',
         'code' => 'error',
         'before' => '[error]',
         'after' => '[/error]',
         'description' => $txt['error_bbc']),
         
         array(
         'image' => 'warning',
         'code' => 'warning',
         'before' => '[warning]',
         'after' => '[/warning]',
         'description' => $txt['warning_bbc']),
         
         array(
         'image' => 'okay',
         'code' => 'okay',
         'before' => '[okay]',
         'after' => '[/okay]',
         'description' => $txt['okay_bbc']),
         
         array(
         'image' => 'info',
         'code' => 'info',
         'before' => '[info]',
         'after' => '[/info]',
         'description' => $txt['info_bbc']),
         array(),

array(
'image' => 'glow',
'code' => 'glow',
'before' => '[glow=red,2,300]',
'after' => '[/glow]',
'description' => $txt['glow']
),
array(
'image' => 'shadow',
'code' => 'shadow',
'before' => '[shadow=red,left]',
'after' => '[/shadow]',
'description' => $txt['shadow']
),
array(
'image' => 'move',
'code' => 'move',
'before' => '[move]',
'after' => '[/move]',
'description' => $txt['marquee']
),
array(),
array(
'image' => 'sup',
'code' => 'sup',
'before' => '[sup]',
'after' => '[/sup]',
'description' => $txt['superscript']
),
array(
'image' => 'sub',
'code' => 'sub',
'before' => '[sub]',
'after' => '[/sub]',
'description' => $txt['subscript']
),
array(
'image' => 'tele',
'code' => 'tt',
'before' => '[tt]',
'after' => '[/tt]',
'description' => $txt['teletype']
),
array(),
array(
'image' => 'tabletrtd',
'code' => 'tabletrtd',
'before' => '[table][tr][td]\n[table][tr][td]\n[table][tr][td]',
'after' => '[/td][td][/td][/tr][/table]\n[/td][/tr][/table]\n',
'description' => $txt['table']
),
array(
'image' => 'tr',
'code' => 'tr',
'before' => '[table][tr][td]\n[table][tr][td]',
'after' => '[/td][td][/td][/tr][/table]\n[/td][/tr][/table]',
'description' => $txt['table_tr']
),
array(
'image' => 'td',
'code' => 'td',
'before' => '[table][tr][td]',
'after' => '[/td][/tr][/table]',
'description' => $txt['table_td']
),
array(
'image' => 'code',
'code' => 'code',
'before' => '[/td][/tr][/table][code]',
'after' => '[/code]',
'description' => $txt['bbc_code']
),
array(
'image' => 'quote',
'code' => 'quote',
'before' => '[quote]',
'after' => '[/quote]',
'description' => $txt['bbc_quote']
),
array(),
array(
'image' => 'list',
'code' => 'list',
'before' => '[list]\n[list][li]',
'after' => '[/li][/list]\n[list][li][/li][/list]\n[/list]',
'description' => $txt['list_unordered']
),
array(
'image' => 'orderlist',
'code' => 'orderlist',
'before' => '[list type=decimal]\n[list][li]',
'after' => '[/li][/list]\n[list][li][/li][/list]\n[/list]',
'description' => $txt['list_ordered']
),
array(
'image' => 'hr',
'code' => 'hr',
'before' => '[hr]',
'description' => $txt['horizontal_rule']
),
);

The example I used was this:
if (allowedTo('view_this'))
echo 'Yes, you can see this.';
else
echo 'Nope, say goodbye';


So I tried this and it didn't work:
if (allowedTo('view_this'))
echo '
array(),
array(
'image' => 'error',
'code' => 'error',
'before' => '[error]',
'after' => '[/error]',
'description' => $txt['error_bbc']),

array(
'image' => 'warning',
'code' => 'warning',
'before' => '[warning]',
'after' => '[/warning]',
'description' => $txt['warning_bbc']),

array(
'image' => 'okay',
'code' => 'okay',
'before' => '[okay]',
'after' => '[/okay]',
'description' => $txt['okay_bbc']),

array(
'image' => 'info',
'code' => 'info',
'before' => '[info]',
'after' => '[/info]',
'description' => $txt['info_bbc']),
array(),';
else
echo 'array(),';


So if someone could help me figure out how to add that in that would be awesome!

I was also wanting to put those BBC Boxes for those bits on another line if that makes sense but have no clue where to start with that.. any help or advice would be greatly appreciated, thank you.
UOFreeshards.net
UOFreeshards.net 2.1 Aplha Test Site
"I believe in Christianity as I believe in the sun...
not because I see it but because by it I see everything else."
C.S. Lewis

Heed what I say, for it shall be mentioned only once.

Angelina Belle

Hello Iomega0318,

I cannot find the section highlighted in red in the quoted section.
I hope you won't mind me moving this to an SMF customization board, where I hope it will attract more attention from others with experience customizing SMF.
Never attribute to malice that which is adequately explained by stupidity. -- Hanlon's Razor

Suki

@Iomega0318 please do use the code tag: [code]code here![/code]  when posting bits of code, makes things easier for everyone.

Which is the specific part you want to modify?

What is the part that you want to be only visible for admins?
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Iomega0318

I will have to redo my post, give me a sec lol.. When it got moved it broke the BBCodes.. and I had only used qoutes because if it's in code tags it won't highlight colors..

**EDIT**
Ok I edited the first post, should be much easier to read now and I deleted most of the code, my file is uploaded as well if you need to see the rest.
UOFreeshards.net
UOFreeshards.net 2.1 Aplha Test Site
"I believe in Christianity as I believe in the sun...
not because I see it but because by it I see everything else."
C.S. Lewis

Heed what I say, for it shall be mentioned only once.

Angelina Belle

#4
I don't know what broke the BBCodes -- they were already broken before I moved your post.
I'm glad you were able to put back the highlighting.

I had always assumed that you chose quote instead of  [code] because you specifically wanted the bbcode highlighting.

I hope you find someone who can help you figure this out.

----------
edit: put [ nobbc] tags around code tag...
Never attribute to malice that which is adequately explained by stupidity. -- Hanlon's Razor

Iomega0318

Quote from: AngelinaBelle on April 09, 2012, 07:49:45 PM
I don't know what broke the BBCodes -- they were already broken before I moved your post.
I'm glad you were able to put back the highlighting.

I had always assumed that you chose quote instead of because you specifically wanted the bbcode highlighting.

I hope you find someone who can help you figure this out.

Were they really lol? I had to fix them once, maybe they broke again when I wasn't looking.. I overloaded SMF with to much coding lol! and yeah sometimes I wish I could use color inside codes though it would have been way easier, and thank you :)
UOFreeshards.net
UOFreeshards.net 2.1 Aplha Test Site
"I believe in Christianity as I believe in the sun...
not because I see it but because by it I see everything else."
C.S. Lewis

Heed what I say, for it shall be mentioned only once.

IchBin™

Iomega0318,

When you want to do something like that, you'll have to do some logic to append to the array. Using echo() only prints something to the page. If you are adding in your BBC like that you will need to append yours to the array.

if (is_allowed('permission')) {
$context['bbc_tags'][] = array(
array(
'image' => 'error',
'code' => 'error',
'before' => '[error]',
'after' => '[/error]',
'description' => $txt['error_bbc']
),
array(
'image' => 'warning',
'code' => 'warning',
'before' => '[warning]',
'after' => '[/warning]',
'description' => $txt['warning_bbc']
),
array(
'image' => 'okay',
'code' => 'okay',
'before' => '[okay]',
'after' => '[/okay]',
'description' => $txt['okay_bbc']
),
array(
'image' => 'info',
'code' => 'info',
'before' => '[info]',
'after' => '[/info]',
'description' => $txt['info_bbc']
),
);
}


Although I'd like to point out, this is exactly why integration hooks were added! If you look at the bottom of that array section you'll see this line:
// Allow mods to modify BBC buttons.
call_integration_hook('integrate_bbc_buttons', array(&$context['bbc_tags']));


This allows you to write a function that takes the $context['bbc_tags'] array as a parameter. You can then append your array as I showed you. All of this can be done without modifying files in SMF. You simply add a row in the smf_settings table in the name as integrate_bbc_buttons with a value being the name of the function that you create to merge your info into the array.
IchBin™        TinyPortal

Iomega0318

Modifying the files seems a bit easier to me for now lol, but I do see what your saying.. Took me a few trys to get it to show where I wanted and get rid of some errors, but other than than it works exactly as intended now and I don't even need the "else" part it simply shows nothing to those who can't use it.. And it's also on it's own line which is what I wanted.. So all-in-all thank you very much you did exactly what I was needing!
UOFreeshards.net
UOFreeshards.net 2.1 Aplha Test Site
"I believe in Christianity as I believe in the sun...
not because I see it but because by it I see everything else."
C.S. Lewis

Heed what I say, for it shall be mentioned only once.

Angelina Belle

Very good, iomega.

Looks like you learned a lot.
AND, because modifying files is actually very difficult (what happens on the next SMF update?)
I highly recommend IchBin's advice to learn how to use that integration hook.
Integration hook = information stored on the database to run your custom code.
It will be EXACTLY as mystifying as what you have struggled with so far, but not any more so.
And you will be thrilled once you figure it out.  I promise.
Never attribute to malice that which is adequately explained by stupidity. -- Hanlon's Razor

IchBin™

Basically all you have to do Iomega is to put that code into a function.  Then in the database you need to add a row into the smf_settings table where the name column is integrate_bbc_buttons and the value is the name of your function. You can put that function at the bottom of the file if you want. At least that way you then don't have to worry about modifying SMF code. The function will automatically be called by the hook code I posted above.
IchBin™        TinyPortal

Iomega0318

I'm going to have to learn some hooks then lol, that seems like it'd be pretty easy and thank you lol I catch on pretty quick to most things.. and after modifying numerous files of every shape size and color over the last 7 years I have to retain a lot :)
UOFreeshards.net
UOFreeshards.net 2.1 Aplha Test Site
"I believe in Christianity as I believe in the sun...
not because I see it but because by it I see everything else."
C.S. Lewis

Heed what I say, for it shall be mentioned only once.

Advertisement: