Customizing SMF > SMF Coding Discussion

How did they give Mod buttons a value of 1

(1/2) > >>

mattizzy:
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);

Arantor:
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.

mattizzy:
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)

mattizzy:
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'),
   );

Arantor:
I thought I explained that: go make the permission first!

Navigation

[0] Message Index

[#] Next page

Go to full version