我的页面分为 4 个部分,每个部分由一个 php 对象的方法生成。
第一部分只显示一个文本并且效果很好,第二个和第四个什么都没有(到目前为止)。
我的问题在于应该显示嵌入式 Google 电子表格的第三部分。
php 页面创建了正确的 html 代码,实际上标题文本正确显示,但 iframe 显示来自 Google 的消息,指出请求的文件不存在。
然后我按Ctrl+U打开页面源(我用的是Firefox),复制文本,粘贴到新的test.html中,保存到服务器,在Firefox中打开新的test.html,现在谷歌喜欢它,并且 iframe 正确显示。
为什么我有两页具有相同来源的页面,但一个有效而另一个无效?
这是页面的完整 php 代码:
<?php
$filename = "parameters-test.txt";
$file_size = filesize($filename);
$handle = fopen($filename, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = str_replace('\"', '"', $content); // ??? why do I need this? And do I need only this? Isn't there some decode function?
$alldata = json_decode($content);
$pages = $alldata->page;
$parameters = $alldata->parameters[0];
$websiteTitle = $parameters->websiteTitle;
$sheets = array();
foreach($pages as $page) {
$sheet = new Sheet();
$sheet->load($page);
array_push($sheets, $sheet);
}
if(isset($_GET["pageId"])) $currentSheet = $_GET["pageId"];
else $currentSheet = 0; // this is the Welcome page
class Sheet {
public $definition = '';
public function load($parameters) {
$this->definition = $parameters;
}
public function showTitle() {
echo '<h1>';
echo $this->definition->title;
echo '</h1>';
echo "\n";
}
public function showHeader() {
if($this->definition->heightHeader) {
echo '<iframe width="';
echo $this->definition->width;
echo '" height="';
echo $this->definition->heightHeader;
echo '" frameborder="0" src="https://docs.google.com/spreadsheet/pub?key=';
echo $this->definition->documentId;
echo '&single=true&gid=';
echo $this->definition->headerSheetId;
echo '&output=html&widget=false&gridlines=false&range=';
echo str_replace(':', '%3AD', $this->definition->rangeHeader);
echo '"></iframe><br />';
echo "\n";
}
}
public function showBody() {
echo '<iframe width="';
echo $this->definition->width;
echo '" height="';
echo $this->definition->heightBody;
echo '" frameborder="0" src="https://docs.google.com/spreadsheet/pub?key=';
echo $this->definition->documentId;
echo '&single=true&gid=';
echo $this->definition->bodySheetId;
echo '&output=html&widget=false&gridlines=false&range=';
echo str_replace(':', '%3AD', $this->definition->rangeBody);
echo '"></iframe><br />';
echo "\n";
}
public function showLinks() {
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="index.css" />
<title><?php echo $websiteTitle; ?></title>
</head>
<body>
<?php
$sheets[$currentSheet]->showTitle();
$sheets[$currentSheet]->showHeader();
$sheets[$currentSheet]->showBody();
$sheets[$currentSheet]->showLinks();
?>
</body>
</html>
这是生成的 html,它仅在来自 test.html 而不是来自 test.php 时才有效:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="index.css" />
<title>this is the title</title>
</head>
<body>
<h1>Hotshots pool league</h1>
<iframe width="500" height="300" frameborder="0" src="https://docs.google.com/spreadsheet/pub?key=0AqEyi7du69LQdHRJXzViMlhEdHVYY2E4X1hnZ21EQ2c&single=true&gid=12&output=html&widget=false&gridlines=false&range=A1%3ADZ999"></iframe><br />
</body>
</html>