1

我在<head> </head>for a 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;
?>

“更新”

这是名为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 代码:

<?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; ?>

这个 headerinclude 文件以这种方式包含在文件 Global.php 中:

// 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")."\";");
4

2 回答 2

2

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

因为 MyBB 不允许<?php ... ?>在模板内使用。但是如果你使用那个插件,你可以,但它有一些限制(你可以在我提供的链接中看到)

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

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

与 MyBB 玩得开心!

于 2014-01-14T02:45:26.180 回答
1

显然,phpBB 会将所有内容放在<?php ?>块中的eval. 在您的情况下,这意味着它会抛出

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

在一个eval. 这是一个未完成的if结构。要修复它,请将整个 PHP 代码放在一个 <?php ?>块中。使用字符串处理或HERE 文档来处理 HTML。

示例 HEREDOC:

<?php 
    if(isset($_REQUEST['url'])):
       $str = <<<EOD
... put your HTML here ...
EOD;
       echo $str;
    endif;
?>
于 2013-01-11T11:27:24.787 回答