Browse Source

article 支持语言

visuddhinanda 4 years ago
parent
commit
45d2d53fbc
4 changed files with 20 additions and 8 deletions
  1. 3 1
      app/article/article.js
  2. 3 1
      app/article/function.php
  3. 12 4
      app/article/my_article.js
  4. 2 2
      app/article/my_article_post.php

+ 3 - 1
app/article/article.js

@@ -34,7 +34,9 @@ function articel_load(id, collection_id) {
 						$("#article_path_title").html(result.title);
 						$("#page_title").text(result.title);
 						$("#article_subtitle").html(result.subtitle);
-						$("#article_author").html(result.username.nickname + "@" + result.username.username);
+						let article_author = result.username.nickname + "@" + result.username.username;
+						article_author += result.lang;
+						$("#article_author").html( article_author );
 						$("#contents").html(note_init(result.content));
 						note_refresh_new();
 						guide_init();

+ 3 - 1
app/article/function.php

@@ -18,6 +18,7 @@ class Article extends Table
 				$output["subtitle"]=$this->redis->hGet("article://".$id,"subtitle");
 				$output["owner"]=$this->redis->hGet("article://".$id,"owner");
 				$output["summary"]=$this->redis->hGet("article://".$id,"summary");
+				$output["lang"]=$this->redis->hGet("article://".$id,"lang");
 				$output["tag"]=$this->redis->hGet("article://".$id,"tag");
 				$output["status"]=$this->redis->hGet("article://".$id,"status");
 				$output["create_time"]=$this->redis->hGet("article://".$id,"create_time");
@@ -25,7 +26,7 @@ class Article extends Table
 				return $output;
 			}
 		}
-        $query = "SELECT id,title,owner,subtitle,summary,tag,status,create_time,modify_time FROM article WHERE id= ? ";
+        $query = "SELECT id,title,owner,subtitle,summary,lang,tag,status,create_time,modify_time FROM article WHERE id= ? ";
         $stmt = $this->dbh->prepare($query);
         $stmt->execute(array($id));
         $output = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -37,6 +38,7 @@ class Article extends Table
 					$this->redis->hSet("article://".$id,"subtitle",$output["subtitle"]);
 				}
 				$this->redis->hSet("article://".$id,"summary",$output["summary"]);
+				$this->redis->hSet("article://".$id,"lang",$output["lang"]);
 				$this->redis->hSet("article://".$id,"owner",$output["owner"]);
 				$this->redis->hSet("article://".$id,"tag",$output["tag"]);
 				$this->redis->hSet("article://".$id,"status",$output["status"]);

+ 12 - 4
app/article/my_article.js

@@ -214,6 +214,14 @@ function my_article_edit(id) {
 					html += '<span id="aritcle_status" style="flex:7;"></span>';
 					html += "</div>";
 
+					let lang;
+					if(typeof result.lang == "undefined"){
+						lang = "en";
+						
+					}else{
+						lang = result.lang;
+					}
+					 
 					html += '<div style="width:100%;display:flex;" >';
 					html +=
 						'<span style="flex:1;margin: auto;">' +
@@ -226,11 +234,11 @@ function my_article_edit(id) {
 						"," +
 						gLocal.gui.example +
 						':Engilish" code="' +
-						result.lang +
+						lang +
 						'" value="' +
-						result.lang +
+						lang +
 						'" >';
-					html +=' <input id="article_lang" type="hidden" name="lang" value="">';
+					html +=' <input id="article_lang" type="hidden" name="lang" value="'+lang+'">';
 					html +='</div>';
 
 					html += "<div style='display:flex;'>";
@@ -273,7 +281,7 @@ function my_article_edit(id) {
 }
 function article_lang_change() {
 	let lang = $("#article_lang_select").val();
-	if (lang.split("-").length == 3) {
+	if (lang.split("_").length == 3) {
 		$("#article_lang").val(lang.split("_")[2]);
 	} else {
 		$("#article_lang").val(lang);

+ 2 - 2
app/article/my_article_post.php

@@ -56,9 +56,9 @@ if(isset($_POST["import"]) && $_POST["import"]=='on'){
 
 PDO_Connect(_FILE_DB_USER_ARTICLE_);
 
-$query="UPDATE article SET title = ? , subtitle = ? , summary = ?, content = ?  , tag = ? , setting = ? , status = ? , receive_time= ?  , modify_time= ?   where  id = ?  ";
+$query="UPDATE article SET title = ? , subtitle = ? , summary = ?, lang = ? , content = ?  , tag = ? , setting = ? , status = ? , receive_time= ?  , modify_time= ?   where  id = ?  ";
 $sth = $PDO->prepare($query);
-$sth->execute(array($_POST["title"] , $_POST["subtitle"] ,$_POST["summary"], $_content , $_POST["tag"] , "{}" , $_POST["status"] ,   mTime() , mTime() , $_POST["id"]));
+$sth->execute(array($_POST["title"] , $_POST["subtitle"] ,$_POST["summary"] ,$_POST["lang"], $_content , $_POST["tag"] , "{}" , $_POST["status"] ,   mTime() , mTime() , $_POST["id"]));
 $respond=array("status"=>0,"message"=>"");
 if (!$sth || ($sth && $sth->errorCode() != 0)) {
 	$error = PDO_ErrorInfo();