*/}}
Browse Source

open graph for generic and twitter

YimingWu 1 year ago
parent
commit
55a1b0778b
1 changed files with 12 additions and 9 deletions
  1. 12 9
      index.php

+ 12 - 9
index.php

@@ -2422,7 +2422,7 @@ blockquote{border-left:2px solid black;}
                 $this->MakeHereButtons($im, true);
             }else{
                 $str = ob_get_clean();
-                $this->MakePageBegin();
+                $this->MakePageBegin($this->NULL_POST);
                 $side = "";
                 if(isset($im['refs'])&&isset($im['refs'][0])){
                     $side.="<span class='small'>".$this->T('该图片出现在')." ".sizeof($im['refs'])." ".$this->T('个帖子中')."</span>";
@@ -2799,13 +2799,16 @@ blockquote{border-left:2px solid black;}
         $this->VisitedHere = $_SESSION[$visited_here];
     }
     
-    function MakePageBegin(){ ?>
+    function MakePageBegin(&$p){ $title=$this->InExperimentalMode?$this->T($this->ExpTitle):
+            ($this->InHereMode?$this->T($this->HereTitle):$this->T($this->Title)) ?>
         <!DOCTYPE html><html lang='zh-Hans-CN'>
         <head>
         <meta charset='utf-8'>
         <meta content="width=device-width, initial-scale=1" name="viewport">
-        <title><?=$this->InExperimentalMode?$this->T($this->ExpTitle):
-            ($this->InHereMode?$this->T($this->HereTitle):$this->T($this->Title))?></title>
+        <title><?=$title?></title>
+        <meta property="og:title" content="<?=$title.(isset($p)?(" | ".$this->GetPostTitle($p)):"")?>">
+        <?php if(isset($p)&&isset($p['hasi'])&&isset($p['hasi'][0])){?> <meta property="twitter:card" content="summary_large_image" />
+            <meta property="og:image" content="<?=(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']==='on'?"https":"http").'://'.$_SERVER['HTTP_HOST'].'/images/thumb/'.$p['hasi'][0]?>"><?php } ?>
         <?php if($this->UseRemoteFont){ ?><style>
 @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Regular.otf") format("opentype");font-weight:normal;}
 @font-face{font-family: "Noto Serif CJK SC";src:url("fonts/NotoSerifSC-Bold.otf") format("opentype");font-weight:bold;}
@@ -2819,7 +2822,7 @@ blockquote{border-left:2px solid black;}
         <div class='page'>
     <?php }
     function MakeHeader(&$p){ 
-        $this->MakePageBegin() ?>
+        $this->MakePageBegin($p) ?>
         <script type='text/javascript'>
             function toggle_mobile_show(a){a.classList.toggle('hidden_m')}
             function ShowWaitingBar(){wait = document.querySelector("#waiting_bar");wait.style.display='';}
@@ -3662,7 +3665,7 @@ blockquote{border-left:2px solid black;}
                         $this->MakeSinglePost($p,true,false,$use_class,false, false, false, true, false, false);
                         if($make_title){?>
                         <script>
-                        document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
+                        document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100)))?>";
                         </script>
                         <?php } if($is_reversed && !$hinted){ ?><?php $hinted = true; 
                         if($this->LoggedIn && (!$this->InHereMode)){ ?>
@@ -3674,7 +3677,7 @@ blockquote{border-left:2px solid black;}
                 }else{
                     $this->MakeSinglePost($post,true, false,"active_post",false, false, false, true, false, false);
                     ?><script>
-                    document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
+                    document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($post),0,100)))?>";
                     </script><?php
                 } $class_add=""; if(isset($post['tid']['first']['no_time'])){ $class_add=' hidden_on_print'; } ?>
                 
@@ -3705,7 +3708,7 @@ blockquote{border-left:2px solid black;}
                         $this->MakeSinglePostExp($p);
                         if($p == $th['first']){?>
                         <script>
-                        document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($p['html']),0,1000)))?>";
+                        document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100)))?>";
                         </script>
                         <?php } if($is_reversed && !$hinted){ ?>
                             <li class='gray smaller bold' style='text-align:center;'>
@@ -3715,7 +3718,7 @@ blockquote{border-left:2px solid black;}
                 }else{
                     $this->MakeSinglePostExp($post);
                     ?><!--<script>
-                    document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr(strip_tags($post['html']),0,1000)))?>";
+                    document.title+=" | <?=addslashes(preg_replace('/\r|\n/u', ' ', mb_substr($this->GetPostTitle($p),0,100)))?>";
                     </script>--><?php
                 } ?>
             </ul>