Advertisement:

Author Topic: How did they give Mod buttons a value of 1  (Read 450 times)

Offline mattizzy

  • Semi-Newbie
  • *
  • Posts: 75
  • Gender: Male
    • mattizzy.okeke on Facebook
    • @mattizzyo on Twitter
How did they give Mod buttons a value of 1
« on: July 12, 2018, 06:32:33 PM »
I want to create my own mod button but I'm experiencing some difficulties.
can_sticky => 'make_sticky'
I don't really understand how make sticky got the value of 1

I created can_feature, if I use can_sticky for
the value, can_feature will have the value 1.

I used print_r($mod_buttons); in Display.template. php to see this.

I want it to have the value 1 with

SOURCES/DISPLAY.PHP
'manage_feature'
$common_permissions = array(
      'can_approve' => 'approve_posts',
      'can_feature' => 'make_sticky',//can_feature=> 1
      'can_feature' => 'manage_feature',//can_feature => empty
      'can_sticky' => 'make_sticky',
      'can_merge' => 'merge_any',
      'can_split' => 'split_any',
      'calendar_post' => 'calendar_post',
      'can_mark_notify' => 'mark_any_notify',
      'can_send_topic' => 'send_topic',
      'can_send_pm' => 'pm_send',
      'can_report_moderator' => 'report_any',
      'can_moderate_forum' => 'moderate_forum',
      'can_issue_warning' => 'issue_warning',
      'can_restore_topic' => 'move_any',
      'can_restore_msg' => 'move_any',
   );
   foreach ($common_permissions as $contextual => $perm)
      $context[$contextual] = allowedTo($perm);
I am only an SMF Addict. I think I took overdose.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,629
    • StoryBB/StoryBB on GitHub
Re: How did they give Mod buttons a value of 1
« Reply #1 on: July 12, 2018, 06:36:01 PM »
The secret is the last part you posted.

It goes through the list of things, e.g. 'can_feature', checks the value of it ('make_sticky'), and specifically checks whether the user has that permission or not (that's what allowedTo does at the end there)

If the user has that permission, it returns true (which outputs as 1) and if the user doesn't, it outputs as false (which is an empty thing)

So you need to create a permission called manage_feature, give it to the user and then can_feature will work as you expect.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline mattizzy

  • Semi-Newbie
  • *
  • Posts: 75
  • Gender: Male
    • mattizzy.okeke on Facebook
    • @mattizzyo on Twitter
Re: How did they give Mod buttons a value of 1
« Reply #2 on: July 12, 2018, 07:07:29 PM »
Sorry but I just wrote 'can_feature' there. how do I give can_feature a value like make sticky. I'm lost.

you said It goes through the list of things, e.g.
'can_feature', checks the value of it
('make_sticky'), and specifically checks
whether the user has that permission or not
(that's what allowedTo does at the end there)
I am only an SMF Addict. I think I took overdose.

Offline mattizzy

  • Semi-Newbie
  • *
  • Posts: 75
  • Gender: Male
    • mattizzy.okeke on Facebook
    • @mattizzyo on Twitter
Re: How did they give Mod buttons a value of 1
« Reply #3 on: July 12, 2018, 07:13:20 PM »
text=> move_topic and the rest of them, has a value. how can I give mine a value.



Display.template.php

$mod_buttons = array(
      'move' => array('test' => 'can_move', 'text' => 'move_topic', 'image' => 'admin_move.gif', 'lang' => true, 'url' => $scripturl . '?action=movetopic;topic=' . $context['current_topic'] . '.0'),
      'feature' => array('test' => 'can_feature', 'text' => 'feature_topic', 'image' => 'admin_move.gif', 'lang' => true, 'url' => $scripturl . '?action=moderate;topic=' . $context['current_topic'] . '.0'),
      'delete' => array('test' => 'can_delete', 'text' => 'remove_topic', 'image' => 'admin_rem.gif', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . $txt['are_sure_remove_topic'] . '\');"', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']),
      'lock' => array('test' => 'can_lock', 'text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.gif', 'lang' => true, 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
      'sticky' => array('test' => 'can_sticky', 'text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.gif', 'lang' => true, 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
      'merge' => array('test' => 'can_merge', 'text' => 'merge', 'image' => 'merge.gif', 'lang' => true, 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']),
      'calendar' => array('test' => 'calendar_post', 'text' => 'calendar_link', 'image' => 'linktocal.gif', 'lang' => true, 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'),
   );
I am only an SMF Addict. I think I took overdose.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,629
    • StoryBB/StoryBB on GitHub
Re: How did they give Mod buttons a value of 1
« Reply #4 on: July 12, 2018, 07:17:54 PM »
I thought I explained that: go make the permission first!
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline mattizzy

  • Semi-Newbie
  • *
  • Posts: 75
  • Gender: Male
    • mattizzy.okeke on Facebook
    • @mattizzyo on Twitter
Re: How did they give Mod buttons a value of 1
« Reply #5 on: July 12, 2018, 07:29:35 PM »
I thought I explained that: go make the permission first!

where will I make permission??
I am only an SMF Addict. I think I took overdose.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,629
    • StoryBB/StoryBB on GitHub
Re: How did they give Mod buttons a value of 1
« Reply #6 on: July 13, 2018, 03:03:08 AM »
Add it to the array of permissions in ManagePermissions.php.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.