Simple Machines Community Forum

Customizing SMF => Graphics and Templates => Aiheen aloitti: the twig - syyskuu 17, 2006, 02:20:27 AP

Otsikko: Custom Tab Problems
Kirjoitti: the twig - syyskuu 17, 2006, 02:20:27 AP
Hi there,

I created a custom tab for my Recent Topics, following the instructions here (http://docs.simplemachines.org/index.php?topic=564.msg927#msg927) and here. (http://www.simplemachines.org/community/index.php?topic=66561.0) The tab works, but the page itself produces a parsing error:

LainaaParse error: parse error, unexpected T_EXIT in /home/content/c/a/s/cassieg6/html/forum/Sources/Rt.php on line 4

Rt.php is a file I created for the custom tab. Here's the code I used for everything:

In my forum index.php, I added:
'rt' => array('Rt.php', 'Rt'),
Otsikko: Re: Custom Tab Problems
Kirjoitti: the twig - syyskuu 17, 2006, 02:23:50 AP
I created a file called Rt.php:
<?php
// Version: 1.1 RC3; Recent Topics

if (!defined('SMF'))
  die(
'Hacking attempt...');

function 
rt() {
        
// This is gonna be needed...
        
loadTemplate('rt');
}
?>
Otsikko: Re: Custom Tab Problems
Kirjoitti: the twig - syyskuu 17, 2006, 02:26:21 AP
And a template called Rt.template.php:
<?php
// Version: 1.1 RC3; RecentTopics

function template_rt()
{
global $context$settings$options$txt$scripturl$modSettings;

// Show the news fader?  (assuming there are things to show...)
if ($settings['show_newsfader'] && !empty($context['fader_news_lines']))
{
echo '
<table border="0" width="100%" class="tborder" cellspacing="' 
, ($context['browser']['is_ie'] || $context['browser']['is_opera6']) ? '1' '0' '" cellpadding="4" style="margin-bottom: 2ex;">
<tr>
<td class="catbg"> &nbsp;'
$txt[102], '</td>
</tr>
<tr>
<td valign="middle" align="center" height="60">'
;

// Prepare all the javascript settings.
echo '
<div id="smfFadeScroller" style="width: 90%; padding: 2px;"><b>'
$context['news_lines'][0], '</b></div>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
// The fading delay (in ms.)
var smfFadeDelay = '
, empty($settings['newsfader_time']) ? 5000 $settings['newsfader_time'], ';
// Fade from... what text color? To which background color?
var smfFadeFrom = {"r": 0, "g": 0, "b": 0}, smfFadeTo = {"r": 255, "g": 255, "b": 255};
// Surround each item with... anything special?
var smfFadeBefore = "<b>", smfFadeAfter = "</b>";

var foreColor, backEl, backColor;

if (typeof(document.getElementById(\'smfFadeScroller\').currentStyle) != "undefined")
{
foreColor = document.getElementById(\'smfFadeScroller\').currentStyle.color.match(/#([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/);
smfFadeFrom = {"r": parseInt(foreColor[1]), "g": parseInt(foreColor[2]), "b": parseInt(foreColor[3])};

backEl = document.getElementById(\'smfFadeScroller\');
while (backEl.currentStyle.backgroundColor == "transparent" && typeof(backEl.parentNode) != "undefined")
backEl = backEl.parentNode;

backColor = backEl.currentStyle.backgroundColor.match(/#([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/);
smfFadeTo = {"r": eval("0x" + backColor[1]), "g": eval("0x" + backColor[2]), "b": eval("0x" + backColor[3])};
}
else if (typeof(window.opera) == "undefined" && typeof(document.defaultView) != "undefined")
{
foreColor = document.defaultView.getComputedStyle(document.getElementById(\'smfFadeScroller\'), null).color.match(/rgb\((\d+), (\d+), (\d+)\)/);
smfFadeFrom = {"r": parseInt(foreColor[1]), "g": parseInt(foreColor[2]), "b": parseInt(foreColor[3])};

backEl = document.getElementById(\'smfFadeScroller\');
while (document.defaultView.getComputedStyle(backEl, null).backgroundColor == "transparent" && typeof(backEl.parentNode) != "undefined" && typeof(backEl.parentNode.tagName) != "undefined")
backEl = backEl.parentNode;

backColor = document.defaultView.getComputedStyle(backEl, null).backgroundColor.match(/rgb\((\d+), (\d+), (\d+)\)/);
smfFadeTo = {"r": parseInt(backColor[1]), "g": parseInt(backColor[2]), "b": parseInt(backColor[3])};
}

// List all the lines of the news for display.
var smfFadeContent = new Array(
"'
implode('",
"'
$context['fader_news_lines']), '"
);
// ]]></script>
<script language="JavaScript" type="text/javascript" src="'
$settings['default_theme_url'], '/fader.js"></script>
</td>
</tr>
</table>'
;
}

// Here's where the "Info Center" starts...
echo '<br />
<div class="tborder" '
$context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? 'style="width: 100%;"' '''>
<div class="catbg" style="padding: 6px; vertical-align: middle; text-align: center; ">
<a href="#" onclick="shrinkHeaderIC(!current_header_ic); return false;"><img id="upshrink_ic" src="'
$settings['images_url'], '/', empty($options['collapse_header_ic']) ? 'collapse.gif' 'expand.gif''" alt="*" title="'$txt['upshrink_description'], '" style="margin-right: 2ex;" align="right" /></a>
'
$txt[685], '
</div>
<div id="upshrinkHeaderIC"'
, empty($options['collapse_header_ic']) ? '' ' style="display: none;"''>
<table border="0" width="100%" cellspacing="1" cellpadding="4" class="bordercolor">'
;

// This is the "Recent Posts" bar.
if (!empty($settings['number_recent_posts']))
{
echo '
<tr>
<td class="titlebg" colspan="2">'
$txt[214], '</td>
</tr>
<tr>
<td class="windowbg" width="20" valign="middle" align="center">
<a href="'
$scripturl'?action=recent"><img src="'$settings['images_url'], '/post/xx.gif" alt="'$txt[214], '" /></a>
</td>
<td class="windowbg2">'
;

// Only show one post.
if ($settings['number_recent_posts'] == 1)
{
// latest_post has link, href, time, subject, short_subject (shortened with...), and topic. (its id.)
echo '
<b><a href="'
$scripturl'?action=recent">'$txt[214], '</a></b>
<div class="smalltext">
'
$txt[234], ' &quot;'$context['latest_post']['link'], '&quot; '$txt[235], ' ('$context['latest_post']['time'], ')<br />
</div>'
;
}
// Show lots of posts.
elseif (!empty($context['latest_posts']))
{
echo '
<table cellpadding="0" cellspacing="0" width="100%" border="0">'
;

/* Each post in latest_posts has:
board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
subject, short_subject (shortened with...), time, link, and href. */
foreach ($context['latest_posts'] as $post)
echo '
<tr>
<td class="middletext" valign="top"><b>'
$post['link'], '</b> '$txt[525], ' '$post['poster']['link'], ' ('$post['board']['link'], ')</td>
<td class="middletext" align="right" valign="top" nowrap="nowrap">'
$post['time'], '</td>
</tr>'
;
echo '
</table>'
;
}
echo '
</td>
</tr>'
;
}

// Show YaBB SP1 style information...
if ($settings['show_sp1_info'])
{
echo '
<tr>
<td class="titlebg" colspan="2">'
$txt[645], '</td>
</tr>
<tr>
<td class="windowbg" width="20" valign="middle" align="center">
<a href="'
$scripturl'?action=stats"><img src="'$settings['images_url'], '/icons/info.gif" alt="'$txt[645], '" /></a>
</td>
<td class="windowbg2" width="100%">
<span class="middletext">
'
$context['common_stats']['total_posts'], ' '$txt[95], ' '$txt['smf88'], ' '$context['common_stats']['total_topics'], ' '$txt[64], ' '$txt[525], ' '$context['common_stats']['total_members'], ' '$txt[19], '. '$txt[656], ': <b> '$context['common_stats']['latest_member']['link'], '</b>
<br /> ' 
$txt[659] . ': <b>&quot;' $context['latest_post']['link'] . '&quot;</b>  ( ' $context['latest_post']['time'] . ' )<br />
<a href="'
$scripturl'?action=recent">'$txt[234], '</a>'$context['show_stats'] ? '<br />
<a href="' 
$scripturl '?action=stats">' $txt['smf223'] . '</a>' '''
</span>
</td>
</tr>'
;
}

// If they are logged in, but SP1 style information is off... show a personal message bar.
if ($context['user']['is_logged'] && !$settings['show_sp1_info'])
{
 echo '
<tr>
<td class="titlebg" colspan="2">'
$txt[159], '</td>
</tr><tr>
<td class="windowbg" width="20" valign="middle" align="center">
'
$context['allow_pm'] ? '<a href="' $scripturl '?action=pm">' '''<img src="'$settings['images_url'], '/message_sm.gif" alt="'$txt[159], '" />'$context['allow_pm'] ? '</a>' '''
</td>
<td class="windowbg2" valign="top">
<b><a href="'
$scripturl'?action=pm">'$txt[159], '</a></b>
<div class="smalltext">
'
$txt[660], ' '$context['user']['messages'], ' '$context['user']['messages'] == $txt[471] : $txt[153], '.... '$txt[661], ' <a href="'$scripturl'?action=pm">'$txt[662], '</a> '$txt[663], '
</div>
</td>
</tr>'
;
}

// Show the login bar. (it's only true if they are logged out anyway.)
if ($context['show_login_bar'])
{
echo '
<tr>
<td class="titlebg" colspan="2">'
$txt[34], ' <a href="'$scripturl'?action=reminder" class="smalltext">(' $txt[315] . ')</a></td>
</tr>
<tr>
<td class="windowbg" width="20" align="center">
<a href="'
$scripturl'?action=login"><img src="'$settings['images_url'], '/icons/login.gif" alt="'$txt[34], '" /></a>
</td>
<td class="windowbg2" valign="middle">
<form action="'
$scripturl'?action=login2" method="post" accept-charset="'$context['character_set'], '" style="margin: 0;">
<table border="0" cellpadding="2" cellspacing="0" align="center" width="100%"><tr>
<td valign="middle" align="left">
<label for="user"><b>'
$txt[35], ':</b><br />
<input type="text" name="user" id="user" size="15" /></label>
</td>
<td valign="middle" align="left">
<label for="passwrd"><b>'
$txt[36], ':</b><br />
<input type="password" name="passwrd" id="passwrd" size="15" /></label>
</td>
<td valign="middle" align="left">
<label for="cookielength"><b>'
$txt[497], ':</b><br />
<input type="text" name="cookielength" id="cookielength" size="4" maxlength="4" value="'
$modSettings['cookieTime'], '" /></label>
</td>
<td valign="middle" align="left">
<label for="cookieneverexp"><b>'
$txt[508], ':</b><br />
<input type="checkbox" name="cookieneverexp" id="cookieneverexp" checked="checked" class="check" /></label>
</td>
<td valign="middle" align="left">
<input type="submit" value="'
$txt[34], '" />
</td>
</tr></table>
</form>
</td>
</tr>'
;
}

echo '
</table>
</div>
</div>'
;

}

?>
Otsikko: Re: Custom Tab Problems
Kirjoitti: the twig - syyskuu 17, 2006, 02:27:48 AP
The tab (which works, but just doesn't go to the right page) was coded in index.template.php as:
if ($context['current_action'] == 'rt')
$current_action = 'rt';
Otsikko: Re: Custom Tab Problems
Kirjoitti: the twig - syyskuu 17, 2006, 02:29:05 AP
and

// Show the [recent topics] button.
echo ($current_action=='rt' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
<td valign="top" class="maintab_' , $current_action == 'rt' ? 'active_back' : 'back' , '">
<a href="', $scripturl, '?action=rt">Recent Topics</a>
</td>' , $current_action == 'rt' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : '';
Otsikko: Re: Custom Tab Problems
Kirjoitti: the twig - syyskuu 17, 2006, 02:31:21 AP
So what am I doing wrong or missing? I would be grateful for any help.

I apologize for the multiple posts. For some reason, my posts kept getting cut off after each coding part, so I had to do them in increments. ???
Otsikko: Re: Custom Tab Problems
Kirjoitti: Ravyn - syyskuu 17, 2006, 11:48:04 IP
it looks to me like you've made this 100x more complicated than it needs to be.

Explain what you're trying to accomplish here? 

From what I can gather, you wanted to add another Tab to the main menu, in this case, called RT, and have that tab take you to a url such as www.yoursite.com/rt.php ? 

Otsikko: Re: Custom Tab Problems
Kirjoitti: the twig - syyskuu 18, 2006, 12:13:55 AP
I probably have made this way too complicated!

Basically, I want to have the Forum Boards and the Recent Topics(Info Center) on separate pages/tabs. Since they are both currently on the Board Index, I believe that I need to create a new page for the Recent Topics to be pulled from (hence the Rt.php and Rt.template.php). The tab I was successful at and works fine, it just doesn't have a correct page to go to, cause of the parsing error in Rt.php.

Does that make sense?
Otsikko: Re: Custom Tab Problems
Kirjoitti: Ravyn - syyskuu 18, 2006, 12:46:40 AP
Ok, so you want to have your regular Forums at www.yoursite.com/forums and then you want to add a Tab that links to a page that displays just the recent posts?

So you want a tab that links to this page --> http://www.simplemachines.org/community/index.php?action=recent as an example?
Otsikko: Re: Custom Tab Problems
Kirjoitti: the twig - syyskuu 18, 2006, 01:16:40 AP
Sort of.

More like a tab that links to the Info Center alone, which I've already reconfigured to show Recent Topics instead of Recent Posts. So, it's like I cut the Board Index in half, and put the Boards on one tab and the Info Center on another. This is to make navigation easier for a site that will be somewhat current news based, people can choose to just navigate the site through the current topics. One caveat is that I want to still be able to control the info center from the Admin console.
Otsikko: Re: Custom Tab Problems
Kirjoitti: Dannii - syyskuu 18, 2006, 01:22:30 AP
There really isn't any unique information in the info centre, are you sure you need it at all?
Otsikko: Re: Custom Tab Problems
Kirjoitti: the twig - syyskuu 18, 2006, 01:30:22 AP
Lainaus käyttäjältä: eldʌkaː - syyskuu 18, 2006, 01:22:30 AP
There really isn't any unique information in the info centre, are you sure you need it at all?

What I want is a way for people to see a long list of the most Recent Topics, with just their titles (not the last post shown), on a separate tab. This is the way I actually prefer to navigate a forum, especially one based around disparate current events/articles/news. It's easy to see where the action is. Since the number of Recent Topics can be customized in the Admin console, I thought it would be easier to keep the Info Center.
Otsikko: Re: Custom Tab Problems
Kirjoitti: Dannii - syyskuu 18, 2006, 01:35:31 AP
I generally use the unread page for that :)
Otsikko: Re: Custom Tab Problems
Kirjoitti: Ravyn - syyskuu 18, 2006, 01:41:42 AP
I agree with eld, this seems kind of redundant.  But if you had enough know how to be able to change hte code for the info center in the first place, it shouldn't be too hard for you to take that code and put it into its own php file, then link your tab to that file.

Change your tab to link to www.mysite.com/rt.php then in the rt.php file place the code for the info center.
Otsikko: Re: Custom Tab Problems
Kirjoitti: the twig - syyskuu 18, 2006, 03:02:11 AP
The Unread page doesn't work for me as-is, because once you read a topic it disappears from the list, plus it only shows unread from your last visit. It makes it, in my opinion, harder to navigate than a straight up most recent topics list. This is a personal preference, but it is my website I'm trying to code. ;)

Raven, putting the Info Center code directly into the rt.php file doesn't work—it gives me an error that it can't find the "main" template. BTW, I've only been doing this a couple weeks, I need pretty precise coding help.

Is there a way to turn the Unread page into just a Recent Topics page? I looked at the array for it in index.php and it includes Recent.php and UnreadTopics, which I'm going to try switching to Recent.php and getLastPosts, and see if that works.
Otsikko: Re: Custom Tab Problems
Kirjoitti: the twig - syyskuu 18, 2006, 03:13:56 AP
Nope, it says I have an error in my SQL syntax.

Can someone help me out, either by helping me figure out the right way to switch the unread action so that Unread Posts becomes Recent Posts(Topics), or with my original complex way of making the Info Center a separate page (Rt.php and Rt.template.php)? I'm already grateful.
Otsikko: Re: Custom Tab Problems
Kirjoitti: the twig - syyskuu 18, 2006, 04:35:45 IP
Actually, Raven's suggestion of the action=recent tab will work, if I can convert recent posts in THAT section to recent topics...I'm off to search the forums for the answer...
Otsikko: Re: Custom Tab Problems
Kirjoitti: the twig - syyskuu 19, 2006, 02:58:02 AP
No luck. Can anyone suggest a way to change action=recent from recent posts to recent topics?