Template variables/switches/loops in php

Tutorials for <a href="http://www.phpbbstyles.com/viewtopic.php?t=356">eXtreme Styles mod</a> for phpBB 2.0.

Moderator: Moderators

Postby PostBot on Tue Jun 22, 2004 7:42 am

There is $forum_id variable. Use this code:
Code: Select all
<?php
global $forum_id;
if($forum_id == 5)
{
?>

this html code will be shown only for forum with id = 5

<?php
}
?>
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby Gogi on Wed Jun 23, 2004 6:28 am

Thank you, all works !
Gogi
Registered User
Registered User
 
Posts: 8
Joined: Tue Jun 22, 2004 2:32 am
Location: made in Russia

Postby bearqst on Thu Jun 24, 2004 9:59 pm

CyberAlien or anyone else,

I have eXtreme mod installed and want to get the following code to run in a block on the portal_body.tpl page.

Code: Select all
<?php

   srand((float) microtime() * 10000000);
$quote = array("Link 1", "Link 2", "Link 3","Link 4");
$echo = array_rand($quote,4);

?>


No matter what I try I can't get it to run in the .tpl files, works fine with a .htm files or as a .php of course.

What am I missing ??

TIA
Keep the wind to ur back and ur powder dry.
bearqst
Registered User
Registered User
 
Posts: 27
Joined: Sat Nov 22, 2003 3:56 pm
Location: Sewards Ice Box

Postby PostBot on Thu Jun 24, 2004 10:25 pm

You have assigned it to variable, not echoed it. So that code shouldn't show anything at all.
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby bearqst on Thu Jun 24, 2004 10:53 pm

Guess I should of included all the code :oops:

Code: Select all
<?php
   srand((float) microtime() * 10000000);
$quote = array("Link 1", "Link 2", "Link 3","Link 4");
$echo = array_rand($quote,4);
?>
<center><h2>
<?
echo $quote[$echo[2]];
?>


I tried adding

Code: Select all
<?php
   
   srand((float) microtime() * 10000000);
$quote = array("Link 1", "Link 2", "Link 3","Link 4");
$echo = array_rand($quote,4);
?>
<center><h2>
<?
global $quote, $echo;
echo $quote[$echo[2]];
?>
Keep the wind to ur back and ur powder dry.
bearqst
Registered User
Registered User
 
Posts: 27
Joined: Sat Nov 22, 2003 3:56 pm
Location: Sewards Ice Box

Postby PostBot on Fri Jun 25, 2004 8:12 am

<? is not allowed. Use <?php instead
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby PostBot on Fri Jun 25, 2004 5:49 pm

Move this code on top of file:
Code: Select all
global $quote, $echo;
and no need to repeat that code. Once per tpl file is enough.
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby bearqst on Fri Jun 25, 2004 6:44 pm

Thank you once again
Keep the wind to ur back and ur powder dry.
bearqst
Registered User
Registered User
 
Posts: 27
Joined: Sat Nov 22, 2003 3:56 pm
Location: Sewards Ice Box

Postby ErDrRon on Thu Jul 01, 2004 9:11 pm

I am writing a MOD that creates a popup window with selected information about a user. I want to be able to allow viewing the button that pops up the window in a users post to be turned on or off within the ACP.

I created a new board configuration field entitled $board_config['myInfo_enable'] that is set to 0 if the function is disabled and to 1 if the function is enabled.

I then added the following code snippet to viewtopic.php:

Code: Select all
// Start - myInfo MOD - ErDrRon
if ( $board_config['myInfo_enable'] == 1 )
{
   $template->assign_block_vars('switch_myInfo_active', array());
}
// End - myInfo MOD - ErDrRon


and the following snippet to viewtopic_body.tpl:

Code: Select all
<!-- BEGIN switch_myInfo_active -->
            {postrow.MY_INFO_IMG}
<!-- END switch_myInfo_active -->


I have tested the value of $board_config['myInfo_enable'] and it does evaluate to 1 when the ACP has the MOD enabled and yet the button does not appear. If I remove the <!-- BEGIN... and <! END... codes and leave just the {postrow.MY_INFO_IMG} then the button shows up. What am I doing wrong?

Cheers!
Ron
:D
User avatar
ErDrRon
Registered User
Registered User
 
Posts: 4
Joined: Tue Jan 20, 2004 6:54 pm

Postby PostBot on Thu Jul 01, 2004 9:54 pm

Replace
Code: Select all
$template->assign_block_vars('switch_myInfo_active', array());
with:
Code: Select all
$template->assign_block_vars('postrow.switch_myInfo_active', array());

And make sure that code in viewtopic.php is inside loop where postrow is assigned.
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby ErDrRon on Thu Jul 01, 2004 10:23 pm

This is what I have now:

viewtopic.php
Code: Select all
$postrow = array();
if ($row = $db->sql_fetchrow($result))
{
   do
   {
      $postrow[] = $row;
      
// Start - myInfo MOD - ErDrRon
      if ( $board_config['myInfo_enable'] == 1 )
      {
         $template->assign_block_vars('postrow.switch_myInfo_active', array());
      }
// End - myInfo MOD - ErDrRon

   }
   while ($row = $db->sql_fetchrow($result));
   $db->sql_freeresult($result);

   $total_posts = count($postrow);
}
else
{
   include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
   sync('topic', $topic_id);

   message_die(GENERAL_MESSAGE, $lang['No_posts_topic']);
}


viewtopic_body.tpl
Code: Select all
      <td class="{postrow.ROW_CLASS}" width="150" align="left" valign="middle"><span class="nav"><a href="#top" class="nav">{L_BACK_TO_TOP}</a></span></td>
      <td class="{postrow.ROW_CLASS}" width="100%" height="28" valign="bottom" nowrap="nowrap"><table cellspacing="0" cellpadding="0" border="0" height="18" width="18">
         <tr>
            <td valign="middle" nowrap="nowrap">{postrow.PROFILE_IMG} {postrow.PM_IMG} {postrow.EMAIL_IMG} {postrow.WWW_IMG} {postrow.AIM_IMG} {postrow.YIM_IMG} {postrow.MSN_IMG}
<!-- BEGIN switch_myInfo_active -->
            {postrow.MY_INFO_IMG}
<!-- END switch_myInfo_active -->
            <script language="JavaScript" type="text/javascript"><!--

   if ( navigator.userAgent.toLowerCase().indexOf('mozilla') != -1 && navigator.userAgent.indexOf('5.') == -1 && navigator.userAgent.indexOf('6.') == -1 )
      document.write(' {postrow.ICQ_IMG}');
   else
      document.write('</td><td>&nbsp;</td><td valign="top" nowrap="nowrap"><div style="position:relative"><div style="position:absolute">{postrow.ICQ_IMG}</div><div style="position:absolute;left:3px;top:-1px">{postrow.ICQ_STATUS_IMG}</div></div>');
            
            //--></script><noscript>{postrow.ICQ_IMG}</noscript></td>
         </tr>
      </table></td>


The button still doesn't show up. Suggestions?

Cheers!
Ron
:D
User avatar
ErDrRon
Registered User
Registered User
 
Posts: 4
Joined: Tue Jan 20, 2004 6:54 pm

Postby PostBot on Fri Jul 02, 2004 9:02 am

You added it to wrong loop. Add it after $template->assign_block_vars('postrow', array(
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby ErDrRon on Fri Jul 02, 2004 5:38 pm

I'm confused. Do I add it as a nested loop such as:

Code: Select all
   $template->assign_block_vars('postrow', array(

                                // Start - myInfo MOD - ErDrRon
                                   if ( $board_config['myInfo_enable'] == 1 )
                                  {
                                       $template->assign_block_vars('postrow.switch_myInfo_active', array());
                                  }
                                // End - myInfo MOD - ErDrRon

      'ROW_COLOR' => '#' . $row_color,
      'ROW_CLASS' => $row_class,
      'POSTER_NAME' => $poster,
      'POSTER_RANK' => $poster_rank,
      'RANK_IMAGE' => $rank_image,
      'POSTER_JOINED' => $poster_joined,
      'POSTER_POSTS' => $poster_posts,
      'POSTER_FROM' => $poster_from,
      'POSTER_AVATAR' => $poster_avatar,
      'POST_DATE' => $post_date,
      'POST_SUBJECT' => $post_subject,
      'MESSAGE' => $message,
      'SIGNATURE' => $user_sig,
      'EDITED_MESSAGE' => $l_edited_by,

      'MINI_POST_IMG' => $mini_post_img,
      'PROFILE_IMG' => $profile_img,
      'PROFILE' => $profile,
      'SEARCH_IMG' => $search_img,
      'SEARCH' => $search,
      'PM_IMG' => $pm_img,
      'PM' => $pm,
      'EMAIL_IMG' => $email_img,
      'EMAIL' => $email,
      'WWW_IMG' => $www_img,
      'WWW' => $www,
      'ICQ_STATUS_IMG' => $icq_status_img,
      'ICQ_IMG' => $icq_img,
      'ICQ' => $icq,
      'AIM_IMG' => $aim_img,
      'AIM' => $aim,
      'MSN_IMG' => $msn_img,
      'MSN' => $msn,
// Start - My Tank MOD - ErDrRon
      'MY_INFO_IMG' => $myInfo_img,
// End - My Tank MOD - ErDrRon
      'YIM_IMG' => $yim_img,
      'YIM' => $yim,
      'EDIT_IMG' => $edit_img,
      'EDIT' => $edit,
      'QUOTE_IMG' => $quote_img,
      'QUOTE' => $quote,
      'IP_IMG' => $ip_img,
      'IP' => $ip,
      'DELETE_IMG' => $delpost_img,
      'DELETE' => $delpost,

      'L_MINI_POST_ALT' => $mini_post_alt,

      'U_MINI_POST' => $mini_post_url,
      'U_POST_ID' => $postrow[$i]['post_id'])
   );


or after that function such as:

Code: Select all
   $template->assign_block_vars('postrow', array(
      'ROW_COLOR' => '#' . $row_color,
      'ROW_CLASS' => $row_class,
      'POSTER_NAME' => $poster,
      'POSTER_RANK' => $poster_rank,
      'RANK_IMAGE' => $rank_image,
      'POSTER_JOINED' => $poster_joined,
      'POSTER_POSTS' => $poster_posts,
      'POSTER_FROM' => $poster_from,
      'POSTER_AVATAR' => $poster_avatar,
      'POST_DATE' => $post_date,
      'POST_SUBJECT' => $post_subject,
      'MESSAGE' => $message,
      'SIGNATURE' => $user_sig,
      'EDITED_MESSAGE' => $l_edited_by,

      'MINI_POST_IMG' => $mini_post_img,
      'PROFILE_IMG' => $profile_img,
      'PROFILE' => $profile,
      'SEARCH_IMG' => $search_img,
      'SEARCH' => $search,
      'PM_IMG' => $pm_img,
      'PM' => $pm,
      'EMAIL_IMG' => $email_img,
      'EMAIL' => $email,
      'WWW_IMG' => $www_img,
      'WWW' => $www,
      'ICQ_STATUS_IMG' => $icq_status_img,
      'ICQ_IMG' => $icq_img,
      'ICQ' => $icq,
      'AIM_IMG' => $aim_img,
      'AIM' => $aim,
      'MSN_IMG' => $msn_img,
      'MSN' => $msn,
// Start - My Tank MOD - ErDrRon
      'MY_INFO_IMG' => $myInfo_img,
// End - My Tank MOD - ErDrRon
      'YIM_IMG' => $yim_img,
      'YIM' => $yim,
      'EDIT_IMG' => $edit_img,
      'EDIT' => $edit,
      'QUOTE_IMG' => $quote_img,
      'QUOTE' => $quote,
      'IP_IMG' => $ip_img,
      'IP' => $ip,
      'DELETE_IMG' => $delpost_img,
      'DELETE' => $delpost,

      'L_MINI_POST_ALT' => $mini_post_alt,

      'U_MINI_POST' => $mini_post_url,
      'U_POST_ID' => $postrow[$i]['post_id'])
   );
// Start - myInfo MOD - ErDrRon
      if ( $board_config['myInfo_enable'] == 1 )
      {
         $template->assign_block_vars('postrow.switch_myInfo_active', array());
      }
// End - myInfo MOD - ErDrRon



Cheers!
Ron
:D
User avatar
ErDrRon
Registered User
Registered User
 
Posts: 4
Joined: Tue Jan 20, 2004 6:54 pm

Postby ErDrRon on Fri Jul 02, 2004 5:42 pm

I answered my own question. It works as in the second code snippet above. Thank you for your help.

Cheers!
Ron
:-)
User avatar
ErDrRon
Registered User
Registered User
 
Posts: 4
Joined: Tue Jan 20, 2004 6:54 pm

Postby xkevinx on Mon Nov 15, 2004 1:18 am

Ok I am trying to figure out what to do here. Im adding a poll block to my portal i designed and i cant figure out how to change some of the loops so that it will parse.
Heres the code. Taken from Smarters exportal.
Code: Select all
<div align="center">
              <div align="center" class="gensmall"><b><?php echo $this->vars[S_POLL_QUESTION];?></b></div>
              <br />
              <!-- BEGIN poll_option_row -->
              <input type="radio" name="vote_id" value="<?php echo $postrow_item[poll_option_row.OPTION_ID];?>" />
              <span class="gensmall"><?php echo $this->vars[poll_option_row.OPTION_TEXT];?>&nbsp;[<?php echo $this->vars[poll_option_row.VOTE_RESULT];?>]</span><br />
              <!-- END poll_option_row -->
              <br />
              <!-- BEGIN switch_user_logged_out -->
              <div align="center">{L_LOGIN_TO_VOTE}</div>
              <!-- END switch_user_logged_out -->
              <!-- BEGIN switch_user_logged_in -->
              <div align="center" class="gensmall">
                <input type="submit" class="mainoption" name="submit2" value="{L_VOTE_BUTTON}" {DISABLED} />
              </div>
              <input type="hidden" name="topic_id" value="{S_TOPIC_ID}" />
              <input type="hidden" name="mode" value="vote" />
              <!-- END switch_user_logged_in -->
              <br />
            </div>

The poll question shows up but non of the other stuff does. What do I need to change to make this work.
xkevinx
Registered User
Registered User
 
Posts: 1
Joined: Mon Nov 15, 2004 1:07 am
Location: California

PreviousNext

Return to eXtreme Styles mod tutorials

Who is online

Users browsing this forum: No registered users and 4 guests

cron