2013-01-11 23 views
1

,我将在这<head> </head>代码为MyBB的论坛:解析错误,插入PHP代码MyBB的

<?php if(isset($_REQUEST['url'])): // <-- only include jQuery if url set ?> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /> 
<script src="http://code.jquery.com/jquery-1.8.3.js"></script> 
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
<script> 
    $(function() { 
    $("#dialog-modal").dialog({ 
     height: 140, 
     modal: true 
    }); 
    }); 
</script> 
<?php endif; ?> 

在页面顶部看到两个错误说

Parse error: syntax error, unexpected $end in /home/content/87/9583687/html/a/global.php(524) : eval()'d code(2) : eval()'d code on line 1 

Parse error: syntax error, unexpected T_ENDIF in /home/content/87/9583687/html/a/global.php(524) : eval()'d code(14) : eval()'d code on line 1 

是第一行代码有问题或语法问题?我的意思是:

<?php if(isset($_REQUEST['url'])): // <-- only include jQuery if url set ?> 

谢谢!

更新::

谢谢!我已经尝试过,但我想我肯定有一些错误? :/

<?php if(isset($_REQUEST['url'])): 
$str = <<<EOD 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /> 
<script src="http://code.jquery.com/jquery-1.8.3.js"></script> 
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
<script> 
    $(function() { 
    $("#dialog-modal").dialog({ 
     height: 140, 
     modal: true 
    }); 
    }); 
</script> 
EOD; 
echo $str; 
endif; 
?> 

“UPDATE”

这是一个名为headerinclude的实际文件:

<link rel="alternate" type="application/rss+xml" title="{$lang->latest_threads} (RSS 2.0)" href="{$mybb->settings['bburl']}/syndication.php" /> 
<link rel="alternate" type="application/atom+xml" title="{$lang->latest_threads} (Atom 1.0)" href="{$mybb->settings['bburl']}/syndication.php?type=atom1.0" /> 
<meta http-equiv="Content-Type" content="text/html; charset={$charset}" /> 
<meta http-equiv="Content-Script-Type" content="text/javascript" /> 
<script type="text/javascript" src="{$mybb->settings['bburl']}/jscripts/prototype.js?ver=1603"></script> 
<script type="text/javascript" src="{$mybb->settings['bburl']}/jscripts/general.js?ver=1603"></script> 
<script type="text/javascript" src="{$mybb->settings['bburl']}/jscripts/popup_menu.js?ver=1600"></script> 
{$stylesheets} 
<script type="text/javascript"> 
<!-- 
    var cookieDomain = "{$mybb->settings['cookiedomain']}"; 
    var cookiePath = "{$mybb->settings['cookiepath']}"; 
    var cookiePrefix = "{$mybb->settings['cookieprefix']}"; 
    var deleteevent_confirm = "{$lang->deleteevent_confirm}"; 
    var removeattach_confirm = "{$lang->removeattach_confirm}"; 
    var loading_text = '{$lang->ajax_loading}'; 
    var saving_changes = '{$lang->saving_changes}'; 
    var use_xmlhttprequest = "{$mybb->settings['use_xmlhttprequest']}"; 
    var my_post_key = "{$mybb->post_code}"; 
    var imagepath = "{$theme['imgdir']}"; 
// --> 
</script> 
{$newpmmsg} 

我要添加下面的代码放在这个文件:

<?php if(isset($_REQUEST['url'])): // <-- only include jQuery if url set ?> 
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /> 
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script> 
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
    <script> 
    $(function() { 
    $("#dialog-modal").dialog({ 
     height: 140, 
     modal: true 
    }); 
    }); 
    </script> 
    <?php endif; ?> 

This heade包含在这样的文件Global.php在rinclude文件:

// Set up some of the default templates 
eval("\$headerinclude = \"".$templates->get("headerinclude")."\";"); 
eval("\$gobutton = \"".$templates->get("gobutton")."\";"); 
eval("\$htmldoctype = \"".$templates->get("htmldoctype", 1, 0)."\";"); 
eval("\$header = \"".$templates->get("header")."\";"); 
+0

它是你的完整文件吗?或者周围有更多的内容。请发布产生此错误的所有内容。 –

+0

嗨,我添加了另一个更新。请看一看。 – Taimoor

+0

什么是错误 –

回答

1

显然,亚历克就会把里面的东西<?php ?>块是在eval。在你的情况下,这意味着它抛出

if(isset($_REQUEST['url'])): 

eval。这是一个未完成的if构造。为了解决这个问题,把整个PHP代码里面一个<?php ?>块。使用字符串处理或HERE documents来执行HTML。

例HEREDOC:

<?php 
    if(isset($_REQUEST['url'])): 
     $str = <<<EOD 
... put your HTML here ... 
EOD; 
     echo $str; 
    endif; 
?> 
+0

谢谢,我该如何处理它? – Taimoor

+0

我用HEREDOC示例更新了我的答案。 –

+0

对不起,我已经更新了上面的代码,请你检查一下吗? – Taimoor

2

我想你会需要这个插件:PHP in Templates/Complex Templates

因为MyBB的不允许使用<?php ... ?>在模板中。但是,如果您使用的插件,你可以,但它有一定的局限性(你可以在我公司提供的链接查看)

这个插件是我见过的MyBB的最强大的插件。例如,如果我不想让客人看到新主题在forumdisplay.php,我只需要在模板更改为:

<if $mybb->user['uid'] != 0 then> 
    <a href="newthread.php?fid={$fid}>New Thread</a> 
</if> 

有乐趣的MyBB!