diff --git a/core/config.defaults.php b/core/config.defaults.php index a9f6277..fd8698c 100644 --- a/core/config.defaults.php +++ b/core/config.defaults.php @@ -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"] = ""; diff --git a/core/controllers/admin/ETSettingsAdminController.class.php b/core/controllers/admin/ETSettingsAdminController.class.php index 711c276..e7e96ee 100644 --- a/core/controllers/admin/ETSettingsAdminController.class.php +++ b/core/controllers/admin/ETSettingsAdminController.class.php @@ -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")); @@ -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"), @@ -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.) @@ -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()); + + } +} } diff --git a/core/lib/ETController.class.php b/core/lib/ETController.class.php index c9145b4..468eb88 100644 --- a/core/lib/ETController.class.php +++ b/core/lib/ETController.class.php @@ -473,6 +473,10 @@ public function render($view = "") if ($logo) $size = getimagesize($logo); $data["forumTitle"] = $logo ? "$title" : $title; + // Add the forum favicon + $favicon = C("esoTalk.forumFavicon"); + $data["forumFavicon"] = ""; + // Add the details for the "back" button. $data["backButton"] = ET::$session->getNavigation($this->navigationId); diff --git a/core/views/admin/settings.php b/core/views/admin/settings.php index 9e2554b..8f17863 100644 --- a/core/views/admin/settings.php +++ b/core/views/admin/settings.php @@ -58,6 +58,13 @@
  • +
  • + +input("forumFaviconImage", "file", array("class" => "text")); ?> +
  • + +
  • +
  • diff --git a/core/views/default.master.php b/core/views/default.master.php index aff24b7..3f8ad58 100644 --- a/core/views/default.master.php +++ b/core/views/default.master.php @@ -16,6 +16,9 @@ <?php echo sanitizeHTML($data["pageTitle"]); ?> + + +