Mod authors: Changes in SMF 2.0: Difference between revisions From Online Manual

Jump to: navigation, search
m (Still requires a lot more cleanup but I started)
(HTML clean up)
Line 1: Line 1:
{{Cleanup html}}
SMF 2.0 has had some large code changes, a lot of which affect how mods are written. Code has been restructured for greater efficiency, several new features have been added (which make certain mods obsolete), etc. Due to the volume of changes, almost all mods designed for SMF 1.1 will not work with SMF 2.0. This document is a short introduction on converting SMF 1.1 mods to SMF 2.0. It is not an exhaustive reference, but should help you get your mod up and running on SMF 2.0.
SMF 2.0 has had some large code changes, a lot of which affect how mods are written. Code has been restructured for greater efficiency, several new features have been added (which make certain mods obsolete), etc. Due to the volume of changes, almost all mods designed for SMF 1.1 will not work with SMF 2.0. This document is a short introduction on converting SMF 1.1 mods to SMF 2.0. It is not an exhaustive reference, but should help you get your mod up and running on SMF 2.0.


==Overview==
== Database Queries ==
<ul class="bbc_list"><li>[[#post_db|Database Queries]]
SMF 1.1 only supported MySQL, and hence, MySQL functions are usually used in mods. In SMF 2.0, a database abstraction layer has been added, allowing for different database systems to be used (at the time of writing, MySQL, PostgreSQL, and SQLite are supported). As such, all MySQL function calls willl need to be changed to use the new SMF functions.
<ul class="bbc_list"><li>[[#post_db_column|Column Names]]</li><li>[[#post_db_query|db_query function]]</li><li>[[#post_db_example|Example]]</li></ul></li><li>[[#post_id_member|$ID_MEMBER removal]]</li><li>[[#post_menu|Menus]]
<ul class="bbc_list"><li>[[#post_menu_main|Main Menu]]</li><li>[[#post_menu_admin|Administration Menu]]</li></ul></li></ul>
<span id="post_db">
<span style="font-size: 4;" class="bbc_size">Database Queries</span></span>----SMF 1.1 only supported MySQL, and hence, MySQL functions are usually used in mods. In SMF 2.0, a database abstraction layer has been added, allowing for different database systems to be used (at the time of writing, MySQL, PostgreSQL, and SQLite are supported). As such, all MySQL function calls willl need to be changed to use the new SMF functions.


Because multiple database systems are supported, it is recommended that you do '''not''' use MySQL-specific SQL features (eg. '''ON DUPLICATE KEY UPDATE'''. If you stick to SQL92 SQL features, you can be assured that your mod ''should'' work on the majority of modern <acronym title="Relational Database Management Systems">RDBMS systems</acronym>.
Because multiple database systems are supported, it is recommended that you do '''not''' use MySQL-specific SQL features (eg. '''ON DUPLICATE KEY UPDATE'''). If you stick to SQL92 SQL features, you can be assured that your mod ''should'' work on the majority of modern <abbr title="Relational Database Management Systems">RDBMS systems</abbr>.


The main functions are listed below:
The main functions are listed below:
<table class="bbc_table"><tr><td>'''Function used in SMF 1.1                                                                   '''</td><td>'''SMF 2.0 equivalent'''</td></tr><tr><td>db_query</td><td>$smcFunc['db_query']</td></tr><tr><td>mysql_fetch_assoc</td><td>$smcFunc['db_fetch_assoc']</td></tr><tr><td>mysql_fetch_row</td><td>$smcFunc['db_fetch_row']</td></tr><tr><td>mysql_num_rows</td><td>$smcFunc['db_num_rows']</td></tr><tr><td>mysql_free_result</td><td>$smcFunc['db_free_result']</td></tr><tr><td>mysql_real_escape_string or mysql_escape_string</td><td>$smcFunc['db_escape_string']</td></tr></table>You will find a more indepth and detailed information about the SMF 2.0 functions in our [[SMF 2.0 Database Functions]] topic on the community forums.
{|
[[#post_overview|Back to overview]]
|-
! Function used in SMF 1.1
! SMF 2.0 equivalent
|-
| db_query
| $smcFunc['db_query']
|-
| mysql_fetch_assoc
| $smcFunc['db_fetch_assoc']
|-
| mysql_fetch_row
| $smcFunc['db_fetch_row']
|-
| mysql_num_rows
| $smcFunc['db_num_rows']
|-
| mysql_free_result
| $smcFunc['db_free_result']
|-
| mysql_real_escape_string or mysql_escape_string
| $smcFunc['db_escape_string']
|}
You will find a more indepth and detailed information about the SMF 2.0 functions in our [[SMF 2.0 Database Functions]] topic on the community forums.


 
=== Column Names ===
=='''Column Names'''==
In SMF 2.0, all uppercase column names have been changed. This was done because some database systems do not support uppercase column names. The index columns that had uppercase names in SMF 1.1 (eg. ID_MSG, ID_TOPIC, ID_MEMBER) have had their names changes to lowercase (id_msg, id_topic, id_member). Additionally, any columns that used camel case (memberName) have changed to use an underscore between words (member_name)
In SMF 2.0, all uppercase column names have been changed. This was done because some database systems do not support uppercase column names. The index columns that had uppercase names in SMF 1.1 (eg. ID_MSG, ID_TOPIC, ID_MEMBER) have had their names changes to lowercase (id_msg, id_topic, id_member). Additionally, any columns that used camel case (memberName) have changed to use an underscore between words (member_name)


An example is below
An example is below
[[#post_overview|Back to overview]]


=='''Code example'''==
=== Code example ===
This code is for SMF 1.1:
This code is for SMF 1.1:
<!--  -->
<pre>echo '
  <ul>';


// Get all the topics in board 1
echo '
$result = db_query("
    &lt;ul&gt;';
  SELECT t.ID_TOPIC, m.posterName, m.subject
  FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m)
// Get all the topics in board 1
  WHERE t.ID_BOARD = 1
$result = db_query("
      AND m.ID_MSG = t.ID_FIRST_MSG
    SELECT t.ID_TOPIC, m.posterName, m.subject
  LIMIT 10", __FILE__, __LINE__);
    FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m)
 
    WHERE t.ID_BOARD = 1
// Loop through all results  
      AND m.ID_MSG = t.ID_FIRST_MSG
while ($row = mysql_fetch_assoc($result))
    LIMIT 10", __FILE__, __LINE__);
{
   
  // Echo this result
// Loop through all results
  echo '
while ($row = mysql_fetch_assoc($result))
      <li>', $row['subject'], ' by ', $row['posterName'], '</li>';
{
}
    // Echo this result
    echo '
      &lt;li&gt;', $row['subject'], ' by ', $row['posterName'], '&lt;/li&gt;';
}
mysql_free_result($result);
echo '
    &lt;/ul&gt;';


mysql_free_result($result);
echo '
  </ul>';
</pre>
And this is the SMF 2.0 equivalent:
And this is the SMF 2.0 equivalent:
<!-- -->
echo '
<pre>echo '
    &lt;ul&gt;';
  <ul>';
 
// Get all the topics in board 1
// Get all the topics in board 1
$result = $smcFunc['db_query']('', "
$result = $smcFunc['db_query']('', "
    SELECT t.id_topic, m.poster_name, m.subject
  SELECT t.id_topic, m.poster_name, m.subject
    FROM {db_prefix}topics AS t
  FROM {db_prefix}topics AS t
      INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
      INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
    WHERE t.id_board = {int:id_board}
  WHERE t.id_board = {int:id_board}
    LIMIT 10",
  LIMIT 10",
    array(
  array(
      'id_board' =&gt; 1,
      'id_board' => 1,
    ));
  ));
   
 
// Loop through all results  
// Loop through all results  
while ($row = $smcFunc['db_fetch_assoc']($result))
while ($row = $smcFunc['db_fetch_assoc']($result))
{
{
    // Echo this result
  // Echo this result
    echo '
  echo '
      &lt;li&gt;', $row['subject'], ' by ', $row['poster_name'], '&lt;/li&gt;';
      <li>', $row['subject'], ' by ', $row['poster_name'], '</li>';
}
}
 
$smcFunc['db_free_result']($result);
$smcFunc['db_free_result']($result);
echo '
    &lt;/ul&gt;';


echo '
== $ID_MEMBER ==
  </ul>';
</pre>[[#post_overview|" class="bbc_link">Back to overview]]
 
 
<span id="post_id">
'''$ID_MEMBER'''
In SMF 1.1, the $ID_MEMBER variable contained the current user's ID. SMF 2.0 has removed this variable. Any code using $ID_MEMBER will need to be edited so it uses either $user_info['id'] or $context['user']['id'].
In SMF 1.1, the $ID_MEMBER variable contained the current user's ID. SMF 2.0 has removed this variable. Any code using $ID_MEMBER will need to be edited so it uses either $user_info['id'] or $context['user']['id'].


<span id="post_menu">
== Menus ==
<span style="font-size: 4;" class="bbc_size">Menus</span></span></span>----<span id="post_menu_main">
=== Main menu ===
'''Main menu'''
In SMF 1.1, each theme had its own main menu in index.template.php. For example, the code for the Calendar button in the SMF 1.1 default theme (Core) looks like this:
In SMF 1.1, each theme had its own main menu in index.template.php. For example, the code for the Calendar button in the SMF 1.1 default theme (Core) looks like this:
</span><pre>  if ($context['allow_calendar'])
    if ($context['allow_calendar'])
      echo ($current_action == 'calendar' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&amp;nbsp;</td>' : '' , '
      echo ($current_action == 'calendar' || $context['browser']['is_ie4']) ? '&lt;td class="maintab_active_' . $first . '"&gt;&amp;nbsp;&lt;/td&gt;' : '' , '
            <td valign="top" class="maintab_' , $current_action == 'calendar' ? 'active_back' : 'back' , '">
            &lt;td valign="top" class="maintab_' , $current_action == 'calendar' ? 'active_back' : 'back' , '"&gt;
              <a href="', $scripturl, '?action=calendar">' , $txt['calendar24'] , '</a>
                &lt;a href="', $scripturl, '?action=calendar"&gt;' , $txt['calendar24'] , '&lt;/a&gt;
            </td>' , $current_action == 'calendar' ? '<td class="maintab_active_' . $last . '">&amp;nbsp;</td>' : '';
            &lt;/td&gt;' , $current_action == 'calendar' ? '&lt;td class="maintab_active_' . $last . '"&gt;&amp;nbsp;&lt;/td&gt;' : '';
</pre>
 
SMF 2.0 has moved all the menu items to Subs.php, in a "setupMenuContext" function. This simplifies theme writing, and makes it easier for mod authors (just edit the Subs.php file, and a button appears on all themes). As an example, the Calendar button has become:
SMF 2.0 has moved all the menu items to Subs.php, in a "setupMenuContext" function. This simplifies theme writing, and makes it easier for mod authors (just edit the Subs.php file, and a button appears on all themes). As an example, the Calendar button has become:
<pre>        'calendar' => array(
        'calendar' =&gt; array(
             'title' => $txt['calendar'],
             'title' =&gt; $txt['calendar'],
             'href' => $scripturl . '?action=calendar',
             'href' =&gt; $scripturl . '?action=calendar',
             'show' => $context['allow_calendar'],
             'show' =&gt; $context['allow_calendar'],
             'sub_buttons' => array(
             'sub_buttons' =&gt; array(
               'view' => array(
               'view' =&gt; array(
                   'title' => $txt['calendar_menu'],
                   'title' =&gt; $txt['calendar_menu'],
                   'href' => $scripturl . '?action=calendar',
                   'href' =&gt; $scripturl . '?action=calendar',
                   'show' => true,
                   'show' =&gt; true,
               ),
               ),
               'post' => array(
               'post' =&gt; array(
                   'title' => $txt['calendar_post_event'],
                   'title' =&gt; $txt['calendar_post_event'],
                   'href' => $scripturl . '?action=calendar;sa=post;sesc=' . $context['session_id'],
                   'href' =&gt; $scripturl . '?action=calendar;sa=post;sesc=' . $context['session_id'],
                   'show' => allowedTo('calendar_post'),
                   'show' =&gt; allowedTo('calendar_post'),
               ),
               ),
             ),
             ),
         ),
         ),
</pre>In Subs.php. A new feature is that each button can have several "sub-buttons". In the future, some themes may render these sub-buttons as a dropdown menu. This is done on the simplemachines.org community forum.
[[#post_overview|" class="bbc_link">Back to overview]]


<span id="post_menu_admin">
In Subs.php. A new feature is that each button can have several "sub-buttons". In the future, some themes may render these sub-buttons as a dropdown menu. This is done on the simplemachines.org community forum.
'''Administration menu'''
 
=== Administration menu ===
In SMF 1.1, the administration menu was defined in the adminIndex() function in Subs.php. For example, the "Forum" section looks like:
In SMF 1.1, the administration menu was defined in the adminIndex() function in Subs.php. For example, the "Forum" section looks like:
</span><pre>  // Admin area 'Forum'.
    // Admin area 'Forum'.
  if (allowedTo(array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum')))
    if (allowedTo(array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum')))
  {
    {
      $context['admin_areas']['layout'] = array(
      $context['admin_areas']['layout'] = array(
        'title' => $txt['layout_controls'],
          'title' =&gt; $txt['layout_controls'],
        'areas' => array()
          'areas' =&gt; array()
      );
      );
      if (allowedTo('manage_boards'))
          $context['admin_areas']['layout']['areas']['manage_boards'] =  '&lt;a href="' . $scripturl . '?action=manageboards"&gt;' . $txt[4] . '&lt;/a&gt;';
      if (allowedTo(array('admin_forum', 'moderate_forum')))
          $context['admin_areas']['layout']['areas']['posts_and_topics'] = '&lt;a href="' . $scripturl . '?action=postsettings"&gt;' . $txt['manageposts'] . '&lt;/a&gt;';
      if (allowedTo('admin_forum'))
      {
          $context['admin_areas']['layout']['areas']['manage_calendar'] = '&lt;a href="' . $scripturl . '?action=managecalendar"&gt;' . $txt['manage_calendar'] . '&lt;/a&gt;';
          $context['admin_areas']['layout']['areas']['manage_search'] = '&lt;a href="' . $scripturl . '?action=managesearch"&gt;' . $txt['manage_search'] . '&lt;/a&gt;';
      }
      if (allowedTo('manage_smileys'))
          $context['admin_areas']['layout']['areas']['manage_smileys'] = '&lt;a href="' . $scripturl . '?action=smileys"&gt;' . $txt['smileys_manage'] . '&lt;/a&gt;';
      if (allowedTo('manage_attachments'))
          $context['admin_areas']['layout']['areas']['manage_attachments'] = '&lt;a href="' . $scripturl . '?action=manageattachments"&gt;' . $txt['smf201'] . '&lt;/a&gt;';
         
    }


      if (allowedTo('manage_boards'))
        $context['admin_areas']['layout']['areas']['manage_boards'] =  '<a href="' . $scripturl . '?action=manageboards">' . $txt[4] . '</a>';
      if (allowedTo(array('admin_forum', 'moderate_forum')))
        $context['admin_areas']['layout']['areas']['posts_and_topics'] = '<a href="' . $scripturl . '?action=postsettings">' . $txt['manageposts'] . '</a>';
      if (allowedTo('admin_forum'))
      {
        $context['admin_areas']['layout']['areas']['manage_calendar'] = '<a href="' . $scripturl . '?action=managecalendar">' . $txt['manage_calendar'] . '</a>';
        $context['admin_areas']['layout']['areas']['manage_search'] = '<a href="' . $scripturl . '?action=managesearch">' . $txt['manage_search'] . '</a>';
      }
      if (allowedTo('manage_smileys'))
        $context['admin_areas']['layout']['areas']['manage_smileys'] = '<a href="' . $scripturl . '?action=smileys">' . $txt['smileys_manage'] . '</a>';
      if (allowedTo('manage_attachments'))
        $context['admin_areas']['layout']['areas']['manage_attachments'] = '<a href="' . $scripturl . '?action=manageattachments">' . $txt['smf201'] . '</a>';
       
  }
</pre>
Much like the main menu, SMF 2.0 has seperated the menu items from the actual menu itself (which is handled by Subs-Menu.php and the theme). The code for this same menu looks a lot simpler in SMF 2.0:
Much like the main menu, SMF 2.0 has seperated the menu items from the actual menu itself (which is handled by Subs-Menu.php and the theme). The code for this same menu looks a lot simpler in SMF 2.0:
<pre>      'layout' => array(
      'layout' =&gt; array(
        'title' => $txt['layout_controls'],
          'title' =&gt; $txt['layout_controls'],
        'permission' => array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum'),
          'permission' =&gt; array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum'),
        'areas' => array(
          'areas' =&gt; array(
            'manageboards' => array(
            'manageboards' =&gt; array(
              'label' => $txt['admin_boards'],
                'label' =&gt; $txt['admin_boards'],
              'file' => 'ManageBoards.php',
                'file' =&gt; 'ManageBoards.php',
              'function' => 'ManageBoards',
                'function' =&gt; 'ManageBoards',
              'permission' => array('manage_boards'),
                'permission' =&gt; array('manage_boards'),
            ),
            ),
            'postsettings' => array(
            'postsettings' =&gt; array(
              'label' => $txt['manageposts'],
                'label' =&gt; $txt['manageposts'],
              'file' => 'ManagePosts.php',
                'file' =&gt; 'ManagePosts.php',
              'function' => 'ManagePostSettings',
                'function' =&gt; 'ManagePostSettings',
              'permission' => array('admin_forum', 'moderate_forum'),
                'permission' =&gt; array('admin_forum', 'moderate_forum'),
            ),
            ),
            'managecalendar' => array(
            'managecalendar' =&gt; array(
              'label' => $txt['manage_calendar'],
                'label' =&gt; $txt['manage_calendar'],
              'file' => 'ManageCalendar.php',
                'file' =&gt; 'ManageCalendar.php',
              'function' => 'ManageCalendar',
                'function' =&gt; 'ManageCalendar',
              'permission' => array('admin_forum'),
                'permission' =&gt; array('admin_forum'),
            ),
            ),
            'managesearch' => array(
            'managesearch' =&gt; array(
              'label' => $txt['manage_search'],
                'label' =&gt; $txt['manage_search'],
              'file' => 'ManageSearch.php',
                'file' =&gt; 'ManageSearch.php',
              'function' => 'ManageSearch',
                'function' =&gt; 'ManageSearch',
              'permission' => array('admin_forum'),
                'permission' =&gt; array('admin_forum'),
            ),
            ),
            'smileys' => array(
            'smileys' =&gt; array(
              'label' => $txt['smileys_manage'],
                'label' =&gt; $txt['smileys_manage'],
              'file' => 'ManageSmileys.php',
                'file' =&gt; 'ManageSmileys.php',
              'function' => 'ManageSmileys',
                'function' =&gt; 'ManageSmileys',
              'permission' => array('manage_smileys'),
                'permission' =&gt; array('manage_smileys'),
            ),
            ),
            'manageattachments' => array(
            'manageattachments' =&gt; array(
              'label' => $txt['attachments_avatars'],
                'label' =&gt; $txt['attachments_avatars'],
              'file' => 'ManageAttachments.php',
                'file' =&gt; 'ManageAttachments.php',
              'function' => 'ManageAttachments',
                'function' =&gt; 'ManageAttachments',
              'permission' => array('manage_attachments'),
                'permission' =&gt; array('manage_attachments'),
            ),
            ),
        ),
          ),
      ),
      ),
</pre>


[[Category:Customizing SMF]]
[[Category:Customizing SMF]]
[[Category:Developing SMF]]
[[Category:Developing SMF]]

Revision as of 22:47, 15 February 2011

SMF 2.0 has had some large code changes, a lot of which affect how mods are written. Code has been restructured for greater efficiency, several new features have been added (which make certain mods obsolete), etc. Due to the volume of changes, almost all mods designed for SMF 1.1 will not work with SMF 2.0. This document is a short introduction on converting SMF 1.1 mods to SMF 2.0. It is not an exhaustive reference, but should help you get your mod up and running on SMF 2.0.

Database Queries

SMF 1.1 only supported MySQL, and hence, MySQL functions are usually used in mods. In SMF 2.0, a database abstraction layer has been added, allowing for different database systems to be used (at the time of writing, MySQL, PostgreSQL, and SQLite are supported). As such, all MySQL function calls willl need to be changed to use the new SMF functions.

Because multiple database systems are supported, it is recommended that you do not use MySQL-specific SQL features (eg. ON DUPLICATE KEY UPDATE). If you stick to SQL92 SQL features, you can be assured that your mod should work on the majority of modern RDBMS systems.

The main functions are listed below:

Function used in SMF 1.1 SMF 2.0 equivalent
db_query $smcFunc['db_query']
mysql_fetch_assoc $smcFunc['db_fetch_assoc']
mysql_fetch_row $smcFunc['db_fetch_row']
mysql_num_rows $smcFunc['db_num_rows']
mysql_free_result $smcFunc['db_free_result']
mysql_real_escape_string or mysql_escape_string $smcFunc['db_escape_string']

You will find a more indepth and detailed information about the SMF 2.0 functions in our SMF 2.0 Database Functions topic on the community forums.

Column Names

In SMF 2.0, all uppercase column names have been changed. This was done because some database systems do not support uppercase column names. The index columns that had uppercase names in SMF 1.1 (eg. ID_MSG, ID_TOPIC, ID_MEMBER) have had their names changes to lowercase (id_msg, id_topic, id_member). Additionally, any columns that used camel case (memberName) have changed to use an underscore between words (member_name)

An example is below

Code example

This code is for SMF 1.1:

echo '
   <ul>';

// Get all the topics in board 1
$result = db_query("
   SELECT t.ID_TOPIC, m.posterName, m.subject
   FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m)
   WHERE t.ID_BOARD = 1
      AND m.ID_MSG = t.ID_FIRST_MSG
   LIMIT 10", __FILE__, __LINE__);
   
// Loop through all results
while ($row = mysql_fetch_assoc($result))
{
   // Echo this result
   echo '
      <li>', $row['subject'], ' by ', $row['posterName'], '</li>';
}

mysql_free_result($result);

echo '
   </ul>';

And this is the SMF 2.0 equivalent:

echo '
   <ul>';

// Get all the topics in board 1
$result = $smcFunc['db_query'](, "
   SELECT t.id_topic, m.poster_name, m.subject
   FROM {db_prefix}topics AS t
      INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
   WHERE t.id_board = {int:id_board}
   LIMIT 10",
   array(
      'id_board' => 1,
   ));
   
// Loop through all results 
while ($row = $smcFunc['db_fetch_assoc']($result))
{
   // Echo this result
   echo '
      <li>', $row['subject'], ' by ', $row['poster_name'], '</li>';
}

$smcFunc['db_free_result']($result);

echo '
   </ul>';

$ID_MEMBER

In SMF 1.1, the $ID_MEMBER variable contained the current user's ID. SMF 2.0 has removed this variable. Any code using $ID_MEMBER will need to be edited so it uses either $user_info['id'] or $context['user']['id'].

Menus

Main menu

In SMF 1.1, each theme had its own main menu in index.template.php. For example, the code for the Calendar button in the SMF 1.1 default theme (Core) looks like this:

   if ($context['allow_calendar'])
      echo ($current_action == 'calendar' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' :  , '
            <td valign="top" class="maintab_' , $current_action == 'calendar' ? 'active_back' : 'back' , '">
               <a href="', $scripturl, '?action=calendar">' , $txt['calendar24'] , '</a>
            </td>' , $current_action == 'calendar' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : ;

SMF 2.0 has moved all the menu items to Subs.php, in a "setupMenuContext" function. This simplifies theme writing, and makes it easier for mod authors (just edit the Subs.php file, and a button appears on all themes). As an example, the Calendar button has become:

        'calendar' => array(
           'title' => $txt['calendar'],
           'href' => $scripturl . '?action=calendar',
           'show' => $context['allow_calendar'],
           'sub_buttons' => array(
              'view' => array(
                 'title' => $txt['calendar_menu'],
                 'href' => $scripturl . '?action=calendar',
                 'show' => true,
              ),
              'post' => array(
                 'title' => $txt['calendar_post_event'],
                 'href' => $scripturl . '?action=calendar;sa=post;sesc=' . $context['session_id'],
                 'show' => allowedTo('calendar_post'),
              ),
           ),
        ),

In Subs.php. A new feature is that each button can have several "sub-buttons". In the future, some themes may render these sub-buttons as a dropdown menu. This is done on the simplemachines.org community forum.

Administration menu

In SMF 1.1, the administration menu was defined in the adminIndex() function in Subs.php. For example, the "Forum" section looks like:

   // Admin area 'Forum'.
   if (allowedTo(array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum')))
   {
      $context['admin_areas']['layout'] = array(
         'title' => $txt['layout_controls'],
         'areas' => array()
      );

      if (allowedTo('manage_boards'))
         $context['admin_areas']['layout']['areas']['manage_boards'] =  '<a href="' . $scripturl . '?action=manageboards">' . $txt[4] . '</a>';

      if (allowedTo(array('admin_forum', 'moderate_forum')))
         $context['admin_areas']['layout']['areas']['posts_and_topics'] = '<a href="' . $scripturl . '?action=postsettings">' . $txt['manageposts'] . '</a>';
      if (allowedTo('admin_forum'))
      {
         $context['admin_areas']['layout']['areas']['manage_calendar'] = '<a href="' . $scripturl . '?action=managecalendar">' . $txt['manage_calendar'] . '</a>';
         $context['admin_areas']['layout']['areas']['manage_search'] = '<a href="' . $scripturl . '?action=managesearch">' . $txt['manage_search'] . '</a>';
      }
      if (allowedTo('manage_smileys'))
         $context['admin_areas']['layout']['areas']['manage_smileys'] = '<a href="' . $scripturl . '?action=smileys">' . $txt['smileys_manage'] . '</a>';

      if (allowedTo('manage_attachments'))
         $context['admin_areas']['layout']['areas']['manage_attachments'] = '<a href="' . $scripturl . '?action=manageattachments">' . $txt['smf201'] . '</a>';
         
   }

Much like the main menu, SMF 2.0 has seperated the menu items from the actual menu itself (which is handled by Subs-Menu.php and the theme). The code for this same menu looks a lot simpler in SMF 2.0:

      'layout' => array(
         'title' => $txt['layout_controls'],
         'permission' => array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum'),
         'areas' => array(
            'manageboards' => array(
               'label' => $txt['admin_boards'],
               'file' => 'ManageBoards.php',
               'function' => 'ManageBoards',
               'permission' => array('manage_boards'),
            ),
            'postsettings' => array(
               'label' => $txt['manageposts'],
               'file' => 'ManagePosts.php',
               'function' => 'ManagePostSettings',
               'permission' => array('admin_forum', 'moderate_forum'),
            ),
            'managecalendar' => array(
               'label' => $txt['manage_calendar'],
               'file' => 'ManageCalendar.php',
               'function' => 'ManageCalendar',
               'permission' => array('admin_forum'),
            ),
            'managesearch' => array(
               'label' => $txt['manage_search'],
               'file' => 'ManageSearch.php',
               'function' => 'ManageSearch',
               'permission' => array('admin_forum'),
            ),
            'smileys' => array(
               'label' => $txt['smileys_manage'],
               'file' => 'ManageSmileys.php',
               'function' => 'ManageSmileys',
               'permission' => array('manage_smileys'),
            ),
            'manageattachments' => array(
               'label' => $txt['attachments_avatars'],
               'file' => 'ManageAttachments.php',
               'function' => 'ManageAttachments',
               'permission' => array('manage_attachments'),
            ),
         ),
      ),


Advertisement: