Skip to content

Commit

Permalink
添加浏览器图标支持
Browse files Browse the repository at this point in the history
  • Loading branch information
skywalker512 committed Jul 13, 2018
1 parent 8a26230 commit 9b04d13
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/config.defaults.php
Expand Up @@ -54,6 +54,7 @@
// Basic forum details.
$config["esoTalk.forumTitle"] = "";
$config["esoTalk.forumLogo"] = false; // Path to an image file to replace the title (don't make it too big or it'll stretch the header!)
$config["esoTalk.forumFavicon"] = false;
$config["esoTalk.language"] = "Chinese";
$config["esoTalk.baseURL"] = "";
$config["esoTalk.cdnURL"] = "";
Expand Down
34 changes: 32 additions & 2 deletions core/controllers/admin/ETSettingsAdminController.class.php
Expand Up @@ -35,6 +35,7 @@ public function action_index()
$form->setValue("cdnURL", C("esoTalk.cdnURL"));
$form->setValue("language", C("esoTalk.language"));
$form->setValue("forumHeader", C("esoTalk.forumLogo") ? "image" : "title");
$form->setValue("forumFavicon", C("esoTalk.forumFavicon"));
$form->setValue("defaultRoute", C("esoTalk.defaultRoute"));
$form->setValue("forumVisibleToGuests", C("esoTalk.visibleToGuests"));
$form->setValue("memberListVisibleToGuests", C("esoTalk.members.visibleToGuests"));
Expand All @@ -60,13 +61,15 @@ public function action_index()
$forumLogo = !empty($_FILES["forumHeaderImage"]['tmp_name']) ? $this->uploadHeaderImage($form) : C("esoTalk.forumLogo");
}
}

$forumFavicon = false;
$forumFavicon = !empty($_FILES["forumFaviconImage"]['tmp_name']) ? $this->uploadFaviconImage($form) : C("esoTalk.forumFavicon");
// Construct an array of config options to write.
$config = array(
"esoTalk.forumTitle" => $form->getValue("forumTitle"),
"esoTalk.cdnURL" => $form->getValue("cdnURL"),
"esoTalk.language" => $form->getValue("language"),
"esoTalk.forumLogo" => $forumLogo,
"esoTalk.forumFavicon" => $forumFavicon,
"esoTalk.defaultRoute" => $form->getValue("defaultRoute"),
"esoTalk.visibleToGuests" => $form->getValue("forumVisibleToGuests"),
"esoTalk.members.visibleToGuests" => $form->getValue("forumVisibleToGuests") and $form->getValue("memberListVisibleToGuests"),
Expand Down Expand Up @@ -111,9 +114,10 @@ protected function uploadHeaderImage($form)

// Validate and get the uploaded file from this field.
$file = $uploader->getUploadedFile("forumHeaderImage");
$str = substr(md5(time()), 0, 4);

// Save it as an image, restricting it to a maximum size.
$logo = $uploader->saveAsImage($file, PATH_UPLOADS."/logo", 500, 26, "max");
$logo = $uploader->saveAsImage($file, PATH_UPLOADS."/logo_$str", 500, 26, "max");
$logo = str_replace(PATH_UPLOADS, "uploads", $logo);

// Delete the old logo (if we didn't just overwrite it.)
Expand All @@ -128,5 +132,31 @@ protected function uploadHeaderImage($form)

}
}
protected function uploadFaviconImage($form)
{
$uploader = ET::uploader();

try {

// Validate and get the uploaded file from this field.
$file = $uploader->getUploadedFile("forumFaviconImage");
$str = substr(md5(time()), 0, 4);

// Save it as an image, restricting it to a maximum size.
$favicon = $uploader->saveAsImage($file, PATH_UPLOADS."/favicon_$str", 64, 64, "max");
$favicon = str_replace(PATH_UPLOADS, "uploads", $favicon);

// Delete the old logo (if we didn't just overwrite it.)
if ($favicon != C("esoTalk.forumFavicon")) @unlink(C("esoTalk.forumFavicon"));

return $favicon;

} catch (Exception $e) {

// If something went wrong up there, add the error message to the form.
$form->error("forumFaviconImage", $e->getMessage());

}
}

}
4 changes: 4 additions & 0 deletions core/lib/ETController.class.php
Expand Up @@ -473,6 +473,10 @@ public function render($view = "")
if ($logo) $size = getimagesize($logo);
$data["forumTitle"] = $logo ? "<img src='".getWebPath($logo)."' {$size[3]} alt='$title'/>" : $title;

// Add the forum favicon
$favicon = C("esoTalk.forumFavicon");
$data["forumFavicon"] = "<link href='".getWebPath($favicon)."' rel='shortcut icon'/>";

// Add the details for the "back" button.
$data["backButton"] = ET::$session->getNavigation($this->navigationId);

Expand Down
7 changes: 7 additions & 0 deletions core/views/admin/settings.php
Expand Up @@ -58,6 +58,13 @@

<li class='sep'></li>

<li>
<label><?php echo T("Forum Favicon"); ?></label>
<?php echo $form->input("forumFaviconImage", "file", array("class" => "text")); ?></label>
</li>

<li class='sep'></li>

<li>
<label><?php echo T("Home page"); ?></label>
<div class='subText'><?php echo T("Choose what people will see when they first visit your forum."); ?></div>
Expand Down
3 changes: 3 additions & 0 deletions core/views/default.master.php
Expand Up @@ -16,6 +16,9 @@
<meta charset='<?php echo T("charset", "utf-8"); ?>'>
<title><?php echo sanitizeHTML($data["pageTitle"]); ?></title>
<?php echo $data["head"]; ?>

<?php echo $data["forumFavicon"]; ?>

</head>

<body class='<?php echo $data["bodyClass"]; ?>'>
Expand Down

0 comments on commit 9b04d13

Please sign in to comment.