2013-01-11 26 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!