Seite 1 von 1

Switch innerhalb Switch

Verfasst: 26.12.2007 19:43
von mark2
Ist es möglich einen Switch wie den logged in innerhalb eines anderen Switch einzubauen? Bei mir funktioniert das nicht.
Ich möchte dass der Button vom Post Report Mod auf der viewtopic_body.tpl für Gäste nicht sichtbar ist.
Theoretisch müsste das mit diesem code (Switch) funktionieren.

Code: Alles auswählen

<!-- BEGIN switch_user_logged_in -->
<!-- END switch_user_logged_in -->
Da ich aber auch den Easy Subforen mod installiert habe steht der post report Button innerhalb des postrow Switch.

Wie blende ich den report Button innerhalb des postrow Switch aus ?
Hier meine viewtopic_body_report.tpl

Verfasst: 26.12.2007 21:31
von Boecki91
Soweit ich weiß muss ein Switch der im Template verschachtelt ist, auch in der entsprechenden PHP-Datei verschachtelt sein.

Verfasst: 26.12.2007 22:44
von mark2
Oh. :oops: Ich glaube da meinst du richtig.
Dachte der loggend in switch funktioniert überall. Ist aber nicht der Fall.

Schade.

Verfasst: 27.12.2007 00:19
von 4seven
Hallo mark2,

1 - Versuch den Post-Report-Button aus dem anderen Switch zu ziehen => örtliche Verlagerung.

2 - Howto für verschachtelte Switches:

# Nested loops/switches
This is where it sometimes gets tricky, and code authors get confused. What happens if you want a loop or a switch inside another loop or switch?

For example, you want to show a list of the first twenty-five users, and their emails, but only show the emails if the user looking at the page is an admin or a moderator? Let's add a bit to our last example:
* PHP-side

Code: Alles auswählen

$sql = "SELECT user_id, username, user_email FROM " . USERS_TABLE . " WHERE user_id >= 1 AND user_id <= 25";
          if ( ! ( $result = $db->sql_query($sql) ) )
          {
             message_die(GENERAL_ERROR, 'Error retrieving user data', '', __LINE__, __FILE__, $sql);
          }
          while ( $row = $db->sql_fetchrow($result) )
          {
             $template->assign_block_vars('user_row',array( 'USERNAME' => htmlspecialchars($row['username']),
                                                            'USER_ID' => $row['user_id'],
                                                            'USER_EMAIL' => $row['user_email']
                                                          )
                                         );
             if ( ($userdata['user_level'] == ADMIN) || ($userdata['user_level'] == MOD) )
             {
                $template->assign_block_vars('user_row.switch_admin_or_mod',array());
             }
          }
* Template-side

Code: Alles auswählen

<table>
          <!-- BEGIN user_row -->
          <tr><td>{user_row.USER_ID}</td><td>{user_row.USERNAME}</td>
          <!-- BEGIN switch_admin_or_mod -->
          <td>{user_row.USER_EMAIL}</td>
          <!-- END switch_admin_or_mod -->
          </tr>
          <!-- END user_row -->
          </table>
Image Some important things to notice are that in the PHP, the name of the switch is 'user_row.switch_admin_or_mod', but in the template, the name is only 'switch_admin_or_mod', which inside 'user_row'. This means that you can't create two switches in the same scope and expect them to work inside each other:
* PHP-side

Code: Alles auswählen

$template->assign_block_vars('switch_user_logged_in',array() );
          $template->assign_block_vars('switch_admin_or_mod',array() );
* Template-side

Code: Alles auswählen

Code: Select all
          <!-- BEGIN switch_user_logged_in -->
          <!-- BEGIN switch_admin_or_mod -->
          some text if it's an admin or mod, logged in
          <!-- END switch_admin_or_mod -->
          <!-- END switch_user_logged_in -->
this won't work, because the template engine will look for 'switch_user_logged_in.switch_admin_or_mod', and it won't find it. One way to do get around this would be:
$template->assign_block_vars('switch_user_logged_in',array() );

*** $template->assign_block_vars('switch_user_logged_in.switch_admin_or_mod',array() );
*** :D
Alternatively, you could have a separate switch altogether. There are actually several different ways of doing this properly, if you think about it.


# Nested loop variables
Just so that you know *** this works (to probably any depth)

Lets say for example you have an array of users, each of which has a name and id attribute, as well as a 'friends' attribute which is an array of the names of their friends, and you want to show the list of users, and who their friends are:


* PHP-side

Code: Alles auswählen

for ($i = 0; $i < count($dataset); $i++ )
          {
               $template->assign_block_vars('user_row', array( 'USER_ID' => $dataset[$i]['user_id'],
                                                               'USER_NAME' => $dataset[$i]['user_name']
                                                             )
                                           );
               for($j = 0; $j < count($dataset[$i]['friends']); $j++ )
               {
                    $template->assign_block_vars('user_row.friend_row',array( 'NAME' => $dataset[$i]['friends'][$j] ) );
               }
          }
* Template-side

Code: Alles auswählen

<table>
          <!-- BEGIN user_row -->
          <tr><td>{user_row.USER_ID}</td><td>{user_row.USERNAME}</td><td><table>
          <!-- BEGIN friend_row -->
          <tr><td>{user_row.friend_row.NAME}</td></tr>
          <!-- END friend_row -->
          </table></td>
          </tr>
          <!-- END user_row -->
          </table>
lg
4seven

Re: Switch innerhalb Switch

Verfasst: 02.02.2009 01:51
von MadiMac
ich habe bei der posting_body.tpl eine option den ich nur für admin und mod sichtbar machen möchte.

Das ist der feld

Code: Alles auswählen

	<!-- BEGIN newtopic --> 
	<tr> 
	  <td class="row1" width="22%"><span class="gen"><b>{L_THUMB}</b></span></td>
	  <td class="row2" width="78%"><span class="gen"><b>{L_THUMB_EXPL}</b></span> <input type="text" name="thumb" size="5" maxlength="5" style="width:50px" tabindex="2" class="post" value="{THUMB}" /></td>
	</tr>
	<!-- END newtopic --> 
So habe ich das gemacht

Code: Alles auswählen

<!-- BEGIN switch_admin_or_mod -->	
<!-- BEGIN newtopic --> 
	<tr> 
	  <td class="row1" width="22%"><span class="gen"><b>{L_THUMB}</b></span></td>
	  <td class="row2" width="78%"><span class="gen"><b>{L_THUMB_EXPL}</b></span> <input type="text" name="thumb" size="5" maxlength="5" style="width:50px" tabindex="2" class="post" value="{THUMB}" /></td>
	</tr>
<!-- END newtopic --> 
<!-- END switch_admin_or_mod -->
Es funktioniert leider nicht das können auch admins und mods auch nicht sehen.

MFG

Re: Switch innerhalb Switch

Verfasst: 02.02.2009 15:09
von jensdd
Ändere mal die Reihenfolge der Switches, also Newtopic nach außen. Ich gehe davon aus, dass du die posting.php nach der Anleitung richtig angepasst hast.

Gruß Jens

Re: Switch innerhalb Switch

Verfasst: 02.02.2009 18:32
von MadiMac
Ehmm Posting.php richtig angepasst ! ich habe da keine änderung gemacht müsste ich dort was eintragen damit sie funktioniert?

Bei der posting.php

gibts dieser stelle

Code: Alles auswählen

$template->assign_block_vars('switch_not_privmsg', array());
if (($post_id == $post_info['topic_first_post_id']) || ($newtopic == '1'))
{
  if  ($post_data['first_post'] != '0')
    {
      $template->assign_block_vars('newtopic', array());
    }
}
ich habe das so geändert

Code: Alles auswählen

$template->assign_block_vars('switch_not_privmsg', array());
if (($post_id == $post_info['topic_first_post_id']) || ($newtopic == '1'))
{
  if  ($post_data['first_post'] != '0')
    {
      $template->assign_block_vars('newtopic', array());
     $template->assign_block_vars('switch_admin_or_mod',array() );
    }
}
Funktioniert auch nicht


das ist der kod für den Mod

Code: Alles auswählen

#
#-----[ OPEN ]------------------------------------------
#
posting.php
#
#-----[ FIND ]------------------------------------------
#
$post_data = array();
switch ( $mode )
{
	case 'newtopic':
#
#-----[ AFTER, ADD ]------------------------------------------
#
    $newtopic = "1"; 
#
#-----[ FIND ]------------------------------------------
#
$select_sql = (!$submit) ? ', t.topic_title, p.enable_bbcode, p.enable_html, p.enable_smilies, p.enable_sig, p.post_username, pt.post_subject, pt.post_text, pt.bbcode_uid, u.username, u.user_id, u.user_sig, u.user_sig_bbcode_uid' : '';
#
#-----[ IN-LINE FIND ]------------------------------------------
#
pt.post_subject
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, pt.post_thumb
#
#-----[ FIND ]------------------------------------------
#
$subject = ( !empty($HTTP_POST_VARS['subject']) ) ? trim($HTTP_POST_VARS['subject']) : '';
#
#-----[ AFTER, ADD ]------------------------------------------
#
$thumb = ( !empty($HTTP_POST_VARS['thumb']) ) ? trim($HTTP_POST_VARS['thumb']) : '';
#
#-----[ FIND ]------------------------------------------
#
prepare_post($mode, $post_data, $bbcode_on, $html_on, $smilies_on, $error_msg, $username, $bbcode_uid, $subject, $message, $poll_title, $poll_options, $poll_length);
#
#-----[ IN-LINE FIND ]------------------------------------------
#
$subject
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, $thumb
#
#-----[ FIND ]------------------------------------------
#
submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id, $topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, $bbcode_uid, str_replace("\'", "''", $username), str_replace("\'", "''", $subject), str_replace("\'", "''", $message), str_replace("\'", "''", $poll_title), $poll_options, $poll_length);
#
#-----[ IN-LINE FIND ]------------------------------------------
#
str_replace("\'", "''", $subject)
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, str_replace("\'", "''", $thumb)
#
#-----[ FIND ]------------------------------------------
#
$subject = ( !empty($HTTP_POST_VARS['subject']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['subject']))) : '';
#
#-----[ AFTER, ADD ]------------------------------------------
#
$thumb = ( !empty($HTTP_POST_VARS['thumb']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['thumb']))) : '';
#
#-----[ FIND ]------------------------------------------
#
$subject = '';
#
#-----[ AFTER, ADD ]------------------------------------------
#
$thumb = '';
#
#-----[ FIND ]------------------------------------------
#
$subject = '';
#
#-----[ AFTER, ADD ]------------------------------------------
#
$thumb = '';
#
#-----[ FIND ]------------------------------------------
#
$subject = ( $post_data['first_post'] ) ? $post_info['topic_title'] : $post_info['post_subject'];
#
#-----[ AFTER, ADD ]------------------------------------------
#
$thumb = $post_info['post_thumb'];
#
#-----[ FIND ]------------------------------------------
#
$subject = ( !empty($subject) ) ? preg_replace($orig_word, $replace_word, $subject) : '';
#
#-----[ AFTER, ADD ]------------------------------------------
#
$thumb = ( !empty($thumb) ) ? preg_replace($orig_word, $replace_word, $thumb) : '';
#
#-----[ FIND ]------------------------------------------
#
$template->assign_block_vars('switch_not_privmsg', array());
#
#-----[ AFTER, ADD ]------------------------------------------
#
$template->assign_block_vars('switch_not_privmsg', array());
if (($post_id == $post_info['topic_first_post_id']) || ($newtopic == '1'))
{
  if  ($post_data['first_post'] != '0')
    {
      $template->assign_block_vars('newtopic', array());
    }
}
#
#-----[ FIND ]------------------------------------------
#
'SUBJECT' => $subject,
#
#-----[ AFTER, ADD ]------------------------------------------
#
	'THUMB' => $thumb,
	'L_THUMB' => $lang['Portal_thumb'],
	'L_THUMB_EXPL' => $lang['Portal_thumb_expl'],
MFG

Re: Switch innerhalb Switch

Verfasst: 02.02.2009 19:10
von jensdd
Versuche mal Folgendes:

Code: Alles auswählen

SUCHE:
---------
if  ($post_data['first_post'] != '0')
{
$template->assign_block_vars('newtopic', array());
}

DANACH EINFÜGEN:
-----------------------
if ( $userdata['user_level'] == ADMIN || $userdata['user_level'] == MOD) 
{ 
$template->assign_block_vars('newtopic.switch_admin_or_mod', array()); 
} 
Im Template muss die Reihenfolge der Switches so aussehen:

<!-- BEGIN newtopic -->
<!-- BEGIN switch_admin_or_mod -->
...
<!-- END switch_admin_or_mod -->
<!-- END newtopic -->

Re: Switch innerhalb Switch

Verfasst: 02.02.2009 20:02
von MadiMac
Joo super besten dank :grin:

MFG