Mercurial > hg > extraction-interface
annotate models/extractapp.php @ 75:75233b09c580 extractapp
saving latest taglist from db according to topic (even when changing topic)
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 09 Apr 2015 15:29:46 +0200 |
parents | 60b5a94163c3 |
children | c49192885290 |
rev | line source |
---|---|
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
2 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
3 <?php |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
4 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
5 class ExtractappModel extends BaseModel{ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
6 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
7 public function Index() { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
8 return array("Index Value 1", "Value 2", "Value 3"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
9 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
10 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
11 protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, |
63
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
12 $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = "",$book_dynasty=""; |
58
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
13 public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
14 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
15 |
53
f9594c240826
get/update text after saving, for xml file consistency
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
52
diff
changeset
|
16 public function GetTextFromFileId() { // remove $_postdata as input |
f9594c240826
get/update text after saving, for xml file consistency
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
52
diff
changeset
|
17 /* |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
18 $this->file_id = $_postdata['fileId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
19 $branch_id = $_postdata['branchId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
20 $section_id = $_postdata['sectionId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
21 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
22 $this->branch_id = $branch_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
23 $this->user_id = $_postdata['userId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
24 $this->section_id = $section_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
25 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
26 $this->section_name = $_postdata['sectionName']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
27 $this->book_id = $_postdata['bookId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
28 $this->book_name = $_postdata['bookName']; |
53
f9594c240826
get/update text after saving, for xml file consistency
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
52
diff
changeset
|
29 */ |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
30 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
31 // get from URL with file_id |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
32 $lg_text_url = $this->get_text_from_fileId_url.$this->file_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
33 //$lg_text = file_get_contents($lg_text_url); |
51
840cdb52f476
add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
48
diff
changeset
|
34 // --- get/set text and parsing meta data from text file |
74
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
35 $lg_text = $this->ParseDataInFile($lg_text_url); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
36 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
37 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
38 $stringInput = $lg_text; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
39 $stringInput = preg_replace("/ /u", "○", $stringInput); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
40 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
41 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$this->book_id."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
42 $lg_text = $stringInput; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
43 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
44 $this->lg_text = $lg_text; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
45 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
46 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
47 |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
48 |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
49 |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
50 |
69
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
51 public function SetBookMetaDataBySectionId() { |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
52 |
69
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
53 // get book_meta from $$this->get_section_metadata_by_sectionId_url |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
54 $section_meta_url = $this->get_section_metadata_by_sectionId_url.$this->section_id; |
69
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
55 $section_meta = json_decode(file_get_contents($section_meta_url), true); |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
56 |
69
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
57 $b = $section_meta['section']['book']; |
63
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
58 |
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
59 $book_meta = array(); |
69
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
60 array_push($book_meta, array($b['id'],$b['name'],$b['level1'],$b['level2'], |
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
61 $b['period'],$b['dynasty'], $b['start_year'], $b['end_year'],$b['line'], |
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
62 $b['volume'],$b['author'], $b['edition'],$b['in_jibengujiku'], $b['admin_type'])); // missing author,year,pagenumber |
63
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
63 $this->book_meta = $book_meta; |
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
64 |
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
65 } |
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
66 |
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
67 |
53
f9594c240826
get/update text after saving, for xml file consistency
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
52
diff
changeset
|
68 public function GetTextFromSectionId() { // remove $_postdata as input |
f9594c240826
get/update text after saving, for xml file consistency
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
52
diff
changeset
|
69 /* |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
70 $section_id = $_postdata['sectionId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
71 $this->section_id = $section_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
72 $this->user_id = $_postdata['userId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
73 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
74 $this->section_name = $_postdata['sectionName']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
75 $this->book_id = $_postdata['bookId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
76 $this->book_name = $_postdata['bookName']; |
53
f9594c240826
get/update text after saving, for xml file consistency
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
52
diff
changeset
|
77 */ |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
78 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
79 // get from URL with file_id |
53
f9594c240826
get/update text after saving, for xml file consistency
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
52
diff
changeset
|
80 // $lg_text_url = $this->get_text_from_sectionId_url.$section_id; |
f9594c240826
get/update text after saving, for xml file consistency
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
52
diff
changeset
|
81 $lg_text_url = $this->get_text_from_sectionId_url.$this->section_id; |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
82 $lg_text = file_get_contents($lg_text_url); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
83 |
51
840cdb52f476
add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
48
diff
changeset
|
84 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
85 $stringInput = $lg_text; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
86 $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
87 $stringInput = preg_replace("/ /u", "○", $stringInput); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
88 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); |
73 | 89 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$this->book_id."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
90 $lg_text = $stringInput; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
91 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
92 $this->lg_text = $lg_text; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
93 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
94 |
74
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
95 |
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
96 // This is only used on localhost |
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
97 public function GetTextFromLocal($_id){ |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
98 $this->section_id = $_id; |
63
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
99 //$this->branch_id = 1; // local test sets branch_id to 1 |
58
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
100 $this->messages['debug'] .= "[Debug] from my local"."<br>"; |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
101 $this->lg_text = $this->GetSectionContent(); |
74
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
102 } |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
103 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
104 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
105 public function GetInfoFromPreviousPage($_postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
106 |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
107 if (isset($_postdata['fileId'])) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
108 $this->file_id = $_postdata['fileId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
109 } |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
110 if (isset($_postdata['sectionId'])) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
111 $this->section_id = $_postdata['sectionId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
112 } |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
113 if (isset($_postdata['text'])) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
114 $this->lg_text = $_postdata['text']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
115 } |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
116 if (isset($_postdata['branchId'])) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
117 $this->branch_id = $_postdata['branchId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
118 } |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
119 if (isset($_postdata['userId'])) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
120 $this->user_id = $_postdata['userId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
121 } |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
122 if (isset($_postdata['topic_id'])) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
123 $this->topic = $_postdata['topic_id']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
124 } |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
125 if (isset($_postdata['sectionName'])) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
126 $this->section_name = $_postdata['sectionName']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
127 } |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
128 if (isset($_postdata['bookName'])) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
129 $this->book_name = $_postdata['bookName']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
130 } |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
131 if (isset($_postdata['bookId'])) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
132 $this->book_id = $_postdata['bookId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
133 } |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
134 if (isset($_postdata['currentFileId'])) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
135 $this->current_fileId = $_postdata['currentFileId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
136 } |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
137 if (isset($_postdata['taglistArray'])) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
138 $this->taglist_infile = json_decode($_postdata['taglistArray']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
139 } |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
140 if (isset($_postdata['book_meta'])) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
141 $this->book_meta = json_decode($_postdata['book_meta']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
142 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
143 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
144 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
145 |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
146 |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
147 private function TaglistSubsetIn($list1, $list2) { // $l1 is a subset of $l2 or not |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
148 // l1 and l2: array( $row['id'], $row['name'], $row['tag'], $row['color'] ) |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
149 $cnt_list1 = count($list1); |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
150 $cnt_list2 = count($list2); |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
151 |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
152 if ($cnt_list1 > $cnt_list2) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
153 return false; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
154 } |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
155 foreach ($list1 as $v1) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
156 $cnt = 0; |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
157 foreach ($list2 as $v2) { |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
158 $num_field = count($v2); |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
159 $matched = true; |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
160 for ($i=0; $i < $num_field; $i++) { |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
161 if ($v1[$i] != $v2[$i]) { |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
162 $matched = false; |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
163 break; |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
164 } |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
165 } |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
166 |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
167 if (!$matched) { |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
168 // not match with this v2 |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
169 $cnt += 1; |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
170 } else { |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
171 break; |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
172 } |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
173 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
174 } |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
175 if ($cnt == $cnt_list2) { |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
176 return false; |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
177 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
178 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
179 return true; |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
180 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
181 } |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
182 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
183 // === for tagging === |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
184 public function StartTagging() { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
185 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
186 $section_id = $this->section_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
187 $stringInput = $this->lg_text; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
188 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
189 $data = array(); // data array to be passed to view |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
190 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
191 //$taglistArray = $this->GetTaglistArray(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
192 //for GetTaglistByTopicID: |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
193 $taglistArray = $this->GetTaglistByTopicID($this->GetTopic()); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
194 |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
195 // $this->taglist_infile is set (1) from file or (2) from _postdata['taglistArray'] which comes from frontend that user decided |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
196 // $this->taglist_infile is the most up-to-date taglist decided by user. Should be written into file. |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
197 if( $this->TaglistSubsetIn($this->taglist_infile, $taglistArray) ) { // TaglistSubsetIn($l1,$l2): $l1 is a subset of $l2 or not |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
198 $this->taglist_infile = ""; |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
199 } |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
200 $data['taglist_infile'] = $this->taglist_infile; // if taglist_infile == "" means taglist in file is up-to-date (will use taglist in db), otherwise means the taglist in file |
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
201 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
202 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
203 // book_meta |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
204 $data['book_meta'] = $this->book_meta; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
205 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
206 // topic list |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
207 $topiclistArray = $this->GetTopiclistArray(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
208 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
209 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
210 $wordlistArray = $this->GetWordlistArray(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
211 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
212 $data['stringInput'] = $stringInput; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
213 $data['taglistArray'] = $taglistArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
214 $data['wordlistArray'] = $wordlistArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
215 $data['section_id'] = $section_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
216 $data['topiclistArray'] = $topiclistArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
217 $data['default_topic_id'] = $this->GetTopic(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
218 $data['topic_tag'] = $this->GetTopicTag($this->GetTopic()); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
219 $data['topic_name'] = $this->GetTopicName($this->GetTopic()); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
220 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
221 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
222 $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
223 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
224 'book_name'=>$this->book_name, 'section_name'=>$this->section_name, |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
225 'current_fileId'=>$this->current_fileId); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
226 |
58
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
227 $this->messages['debug'] .= "[Debug] "; |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
228 $this->messages['debug'] .= "file_id=".$this->file_id.", section_id=".$this->section_id; |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
229 $this->messages['debug'] .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic; |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
230 $this->messages['debug'] .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name; |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
231 $this->messages['debug'] .= ", current_fileId=".$this->current_fileId."<br>"; |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
232 |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
233 $this->messages['info'] .= "[Info] book name: ".$this->book_name; |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
234 $this->messages['info'] .= ", section id: ". $this->section_id; |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
235 $this->messages['info'] .= ", branch id: ".$this->branch_id; |
60
3239979f6673
New: 1.display messages(style) 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
59
diff
changeset
|
236 $this->messages['info'] .= ", file id: ".$this->file_id; |
58
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
237 $this->messages['info'] .= "<br>"; |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
238 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
239 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
240 $data['messages'] = $this->messages; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
241 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
242 return $data; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
243 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
244 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
245 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
246 public function SaveFullText($postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
247 if ($postdata['text']){ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
248 $date = date('Y_m_d_H_i_s', time()); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
249 if ( file_exists("data/parsing_files/".$postdata['filename'].".txt") ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
250 $oldFile = file_get_contents("data/parsing_files/".$postdata['filename'].".txt"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
251 file_put_contents("data/parsing_files/".$postdata['filename']."_".$date.".txt", $oldFile); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
252 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
253 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
254 if (get_magic_quotes_gpc()) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
255 $require = stripslashes($postdata['text']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
256 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
257 $require = $postdata['text']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
258 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
259 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
260 $require = preg_replace("/【<a(.*?)>(.*?)<\/a>】/u", "【\\2】", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
261 $require = preg_replace('/&/u', "&", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
262 $require = preg_replace("/○/u", " ", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
263 $require = preg_replace("/<br>/u", "\n", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
264 $require = preg_replace("/<br>/u", "\n", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
265 file_put_contents("data/parsing_files/".$postdata['filename'].".txt", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
266 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
267 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
268 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
269 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
270 public function UpdateInfoByResponseFromLGService($response) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
271 |
73 | 272 if (isset($response["file"])) { |
273 $response_file = $response["file"]; | |
274 } | |
275 if (isset($response["branch"])) { | |
276 $response_branch = $response["branch"]; | |
277 } | |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
278 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
279 $status = (string)$response["status"]; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
280 if ($status == "ok") { |
58
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
281 $this->messages['info'] .= "[Info] Saving success. <br>"; |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
282 $this->file_id = (string)$response_file["id"]; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
283 $this->branch_id = (string)$response_branch["id"]; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
284 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
285 } else if ($status == "error") { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
286 // saving not success |
61
c6fa7f83c5bf
New: 1.display messages(style) 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
60
diff
changeset
|
287 $this->messages['error'] .= "[Error] Saving Failed! ".(string)$response["message"]."<br>"; |
66
e71a437ae49f
New: responsive. some css style
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
65
diff
changeset
|
288 $this->messages['warning'] .= "[Warning] Please check branch ".$this->branch_id." in LGService, and modify from the latest version."; |
58
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
289 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
290 $response_currentFile = $response["currentFile"]; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
291 $this->current_fileId = (string)$response_currentFile["id"]; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
292 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
293 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
294 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
295 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
296 } |
57
5cf9720a2e25
New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
56
diff
changeset
|
297 |
5cf9720a2e25
New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
56
diff
changeset
|
298 public function ReloadSetting() { |
5cf9720a2e25
New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
56
diff
changeset
|
299 if ($this->current_fileId != 0) { |
5cf9720a2e25
New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
56
diff
changeset
|
300 $this->file_id = $this->current_fileId; |
5cf9720a2e25
New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
56
diff
changeset
|
301 $this->current_fileId = 0; |
5cf9720a2e25
New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
56
diff
changeset
|
302 } |
5cf9720a2e25
New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
56
diff
changeset
|
303 } |
5cf9720a2e25
New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
56
diff
changeset
|
304 |
75
75233b09c580
saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
74
diff
changeset
|
305 // This is only called by SaveFullTextToLGService() |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
306 private function AppendMetaData($text_content) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
307 $text = '<?xml version="1.0" encoding="UTF-8"?>'; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
308 $text .= "\n<text>\n"; |
75
75233b09c580
saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
74
diff
changeset
|
309 // --- topic --- |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
310 $text .= "<topic>".$this->topic."</topic>\n"; |
75
75233b09c580
saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
74
diff
changeset
|
311 // --- book meta data --- |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
312 $book = $this->book_meta; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
313 foreach ($book as $b) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
314 $text .= "<book>\n"; |
51
840cdb52f476
add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
48
diff
changeset
|
315 $text .= "<id>".$b[0]."</id>\n"; |
840cdb52f476
add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
48
diff
changeset
|
316 $text .= "<name>".$b[1]."</name>\n"; |
69
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
317 $text .= "<level1>".$b[2]."</level1>\n"; |
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
318 $text .= "<level2>".$b[3]."</level2>\n"; |
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
319 $text .= "<period>".$b[4]."</period>\n"; |
63
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
320 $text .= "<dynasty>".$b[5]."</dynasty>\n"; |
69
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
321 $text .= "<start_year>".$b[6]."</start_year>\n"; |
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
322 $text .= "<end_year>".$b[7]."</end_year>\n"; |
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
323 $text .= "<line>".$b[8]."</line>\n"; |
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
324 $text .= "<volume>".$b[9]."</volume>\n"; |
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
325 $text .= "<author>".$b[10]."</author>\n"; |
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
326 $text .= "<edition>".$b[11]."</edition>\n"; |
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
327 $text .= "<in_jibengujiku>".$b[12]."</in_jibengujiku>\n"; |
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
328 $text .= "<admin_type>".$b[13]."</admin_type>\n"; |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
329 $text .= "</book>\n"; |
69
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
330 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
331 } |
75
75233b09c580
saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
74
diff
changeset
|
332 |
75233b09c580
saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
74
diff
changeset
|
333 // ---- taglist --- |
75233b09c580
saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
74
diff
changeset
|
334 // $taglist = $this->taglist_infile; |
75233b09c580
saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
74
diff
changeset
|
335 // obtain the latest taglist from db |
75233b09c580
saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
74
diff
changeset
|
336 $taglist = $this->GetTaglistByTopicID($this->GetTopic()); |
75233b09c580
saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
74
diff
changeset
|
337 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
338 foreach ($taglist as $tagitem) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
339 $text .= "<tagitem>\n"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
340 $text .= "<id>".$tagitem[0]."</id>\n"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
341 $text .= "<name>".$tagitem[1]."</name>\n"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
342 $text .= "<tag>".$tagitem[2]."</tag>\n"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
343 $text .= "<color>".$tagitem[3]."</color>\n"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
344 $text .= "</tagitem>\n"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
345 } |
75
75233b09c580
saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
74
diff
changeset
|
346 // ---- |
75233b09c580
saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
74
diff
changeset
|
347 // --- text_content --- |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
348 $text .= $text_content; |
65
f9ae94a9b041
New: adding topic names: name_en, name_ch, name_pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
63
diff
changeset
|
349 $text .= "</text>"; |
75
75233b09c580
saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
74
diff
changeset
|
350 // ---- |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
351 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
352 return $text; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
353 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
354 public function SaveFullTextToLGService($_postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
355 // save tagged text (full text) by Jorge's API to lg service |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
356 // -------- |
58
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
357 global $AT_LOCAL; |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
358 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
359 if ($_postdata['text']){ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
360 $date = date('Y_m_d_H_i_s', time()); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
361 if ( file_exists("data/parsing_files/".$_postdata['sectionId'].".txt") ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
362 $oldFile = file_get_contents("data/parsing_files/".$_postdata['sectionId'].".txt"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
363 //saving in my local machine in developing phrase |
58
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
364 if ($AT_LOCAL) { |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
365 file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile); |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
366 } |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
367 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
368 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
369 if (get_magic_quotes_gpc()) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
370 $require = stripslashes($_postdata['text']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
371 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
372 $require = $_postdata['text']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
373 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
374 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
375 $require = preg_replace("/【<a(.*?)>(.*?)<\/a>】/u", "【\\2】", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
376 $require = preg_replace('/&/u', "&", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
377 $require = preg_replace("/○/u", " ", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
378 $require = preg_replace("/<br>/u", "\n", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
379 //$require = preg_replace("/<br>/u", "\n", $require); |
55
e930eb88b547
bug fixed: when addTagTitle, removing self-closing tag which causes error in coloring tag
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
54
diff
changeset
|
380 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
381 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
382 if ($_postdata['branchId'] == 0) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
383 // -- new branch case |
65
f9ae94a9b041
New: adding topic names: name_en, name_ch, name_pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
63
diff
changeset
|
384 $require = "<text_content>".$require."</text_content>\n"; |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
385 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
386 $require = $this->AppendMetaData($require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
387 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
388 //saving in my local machine in developing phrase |
58
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
389 if ($AT_LOCAL) { |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
390 file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require); |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
391 } |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
392 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
393 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
394 // ------ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
395 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
396 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
397 if ($_postdata['branchId'] != 0) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
398 // -- exiting branch case |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
399 $postfields = array( |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
400 "text" => $require, |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
401 "branchId" => $_postdata['branchId'], |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
402 "userId" => $_postdata['userId'], |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
403 "userPreviousFileId" => $_postdata['fileId'], |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
404 ); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
405 $save_url = $this->save_to_LGService_url; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
406 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
407 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
408 // -- new branch case |
59
6e44605eb4f6
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
58
diff
changeset
|
409 // echo "saveNew!"; |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
410 $user_id = "0"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
411 if ($_postdata['userId']) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
412 $user_id = $_postdata['userId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
413 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
414 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
415 $postfields = array( |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
416 "text" => $require, |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
417 "sectionId" => $_postdata['sectionId'], |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
418 "userId" => $user_id, |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
419 "label" => $_postdata['label'], |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
420 ); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
421 $save_url = $this->save_new_to_LGService_url; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
422 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
423 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
424 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
425 // set up the curl resource |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
426 $ch = curl_init(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
427 curl_setopt($ch, CURLOPT_URL, $save_url); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
428 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
429 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
430 curl_setopt($ch, CURLOPT_POST, true); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
431 curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
432 //curl_setopt($ch, CURLOPT_HEADER, true); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
433 curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
434 'Content-type: multipart/form-data;charset=utf-8' |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
435 )); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
436 |
58
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
437 if (!$AT_LOCAL) { |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
438 // execute the request |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
439 $output = curl_exec($ch); |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
440 } |
a11f9103b8db
New: 1.display messages 2.handle saving conflict:up-to-date or reload text
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
57
diff
changeset
|
441 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
442 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
443 // output the profile information - includes the header |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
444 //echo($output) . PHP_EOL; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
445 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
446 // close curl resource to free up system resources |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
447 curl_close($ch); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
448 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
449 $response = json_decode($output, true); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
450 return $response; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
451 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
452 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
453 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
454 // --- for regex ---- |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
455 public function GetRegexFilenameById($topic_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
456 $query = sprintf("SELECT regex_filename FROM `topic_regex_relation` WHERE topic_id=\"%s\"", $topic_id); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
457 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
458 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
459 return json_encode("Failed during selecting topic_regex_relation table."); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
460 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
461 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
462 $filenames = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
463 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
464 array_push($filenames, $row['regex_filename']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
465 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
466 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
467 return $filenames; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
468 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
469 public function SmartRegexLoad($topic_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
470 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
471 // Load regex file based on current topic. Only shows the regex in this topic -- |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
472 $filenames = $this->GetRegexFilenameById($topic_id); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
473 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
474 // Get regex file from filesystem ---- |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
475 $data_path = "./data/"; // get the current file path, which is getcwd(), and concatenate with "/data/" |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
476 $returnArray = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
477 $files1 = scandir($data_path."regex_files"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
478 foreach ( $files1 as $file ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
479 if ( $file != "." && $file != ".." && $file != ".DS_Store") { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
480 foreach ($filenames as $filename) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
481 if ($file == $filename) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
482 $returnArray[preg_replace("/\.txt/", "", $file)] = file_get_contents( $data_path."regex_files/".$file ); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
483 break; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
484 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
485 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
486 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
487 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
488 echo json_encode($returnArray); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
489 return; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
490 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
491 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
492 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
493 public function SmartRegexSave($_postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
494 if ($_postdata['text']){ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
495 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
496 // --- update topic_regex_relation table --- |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
497 $topic_id = $_postdata['topic_id']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
498 $filename = $_postdata['filename'].'.txt'; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
499 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
500 // check if already existing a record for this regex file |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
501 $query = "SELECT * FROM topic_regex_relation WHERE topic_id=".$topic_id." AND regex_filename='".$filename."'"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
502 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
503 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
504 echo json_encode("ErrorDB"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
505 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
506 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
507 if ($row && !$_postdata['forcesave']) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
508 // promt user a comfirm to force saving or not |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
509 echo json_encode("ForceSave"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
510 return; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
511 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
512 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
513 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
514 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
515 if (!$_postdata['forcesave']) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
516 $query = "INSERT INTO topic_regex_relation (topic_id, regex_filename) VALUES (".$topic_id.",'".$filename."')"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
517 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
518 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
519 echo json_encode("ErrorDB"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
520 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
521 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
522 // --- write to filesystem --- |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
523 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
524 /* |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
525 $date = date('Y_m_d_H_i_s', time()); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
526 if ( file_exists("regex_files/".$_POST['filename'].".txt") ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
527 $oldFile = file_get_contents("regex_files/".$_POST['filename'].".txt"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
528 file_put_contents("regex_files/".$_POST['filename']."_".$date.".txt", $oldFile); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
529 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
530 */ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
531 $data_path = "./data/"; // get the current file path, which is getcwd(), and concatenate with "/data/" |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
532 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
533 if (get_magic_quotes_gpc()) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
534 $require = stripslashes($_postdata['text']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
535 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
536 $require = $_postdata['text']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
537 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
538 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
539 file_put_contents( $data_path."regex_files/".$_postdata['filename'].".txt", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
540 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
541 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
542 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
543 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
544 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
545 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
546 // === for export table === |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
547 public function ExportTable($postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
548 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
549 $content = $postdata['content']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
550 $topic = $postdata['topic']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
551 $section_id = $postdata['sectionId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
552 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
553 //$section_id = $this->section_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
554 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
555 $sectionName = $postdata['sectionName']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
556 $bookId = $postdata['bookId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
557 $bookName = $postdata['bookName']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
558 |
63
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
559 // ===== |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
560 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
561 $outputTableArray = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
562 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
563 //$taglistArray = $this->GetTaglistArray(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
564 $taglistArray = $this->GetTaglistByTopicID($topic); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
565 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
566 $outputTableArray[0]=array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
567 $outputTableArray[0][0]=array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
568 $outputTableArray[0][1]=array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
569 foreach ( $taglistArray as $value ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
570 $outputTableArray[0][0][$value[2]] = $value[1]; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
571 $outputTableArray[0][1][$value[2]] = $value[1]."(Title)"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
572 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
573 $outputTableArray[0]["other"] = "其他"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
574 $outputTableArray[0]["page"] = "頁數"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
575 $outputTableArray[0]["full"] = "全文"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
576 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
577 foreach ( $taglistArray as $tagValue ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
578 $content = preg_replace("/<\/".$tagValue[2].">○*<".$tagValue[2].">/u", "", $content); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
579 $content = preg_replace("/<".$tagValue[2].">[ ]*<\/".$tagValue[2].">/u", "", $content); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
580 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
581 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
582 $contentLineArray = explode( "<br>", $content ); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
583 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
584 $count=0; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
585 $pageNow=NULL; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
586 foreach ( $contentLineArray as $value ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
587 $count++; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
588 $recordString = $value; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
589 $otherString = $recordString; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
590 //echo $recordString."<br>\n"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
591 if ( preg_match("/【<a(.*?)>(.*?)<\/a>】/u", $recordString, $matches) ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
592 $pageNow = $matches[2]; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
593 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
594 foreach ( $taglistArray as $tagValue ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
595 if ( preg_match_all("/<".$tagValue[2].">(.*?)<\/".$tagValue[2].">/u", $recordString, $matches, PREG_SET_ORDER) ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
596 foreach ( $matches as $matchesValue ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
597 $matchesValue[1] = preg_replace("/○/u", "", $matchesValue[1]); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
598 if ( preg_match_all("/〈(.*?)〉/u", $matchesValue[1], $matches2, PREG_SET_ORDER) ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
599 foreach ( $matches2 as $matches2Value ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
600 if ( isset($outputTableArray[$count][0][$tagValue[2]]) ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
601 $outputTableArray[$count][0][$tagValue[2]] .= ";".$matches2Value[1]; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
602 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
603 $outputTableArray[$count][0][$tagValue[2]] = $matches2Value[1]; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
604 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
605 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
606 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
607 if ( isset($outputTableArray[$count][0][$tagValue[2]]) ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
608 $outputTableArray[$count][0][$tagValue[2]] .= ";".$matchesValue[1]; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
609 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
610 $outputTableArray[$count][0][$tagValue[2]] = $matchesValue[1]; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
611 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
612 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
613 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
614 $otherString = preg_replace("/<".$tagValue[2].">(.*?)<\/".$tagValue[2].">/u", " ", $otherString); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
615 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
616 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
617 $otherString = preg_replace("/○/u", "", $otherString); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
618 $outputTableArray[$count]["other"] = $otherString; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
619 $outputTableArray[$count]["page"] = $pageNow; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
620 $value = preg_replace("/>/u", ">", $value); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
621 $value = preg_replace("/</u", "<", $value); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
622 $outputTableArray[$count]["full"] = $value; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
623 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
624 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
625 $topic_tag = $this->GetTopicTag($topic); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
626 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
627 foreach ( $outputTableArray as $arrayIndex => $arrayValue ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
628 // output each row which the topic tag |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
629 // e.g. the original version is for 'person' |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
630 if ( !isset($arrayValue[0][$topic_tag]) ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
631 unset($outputTableArray[$arrayIndex]); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
632 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
633 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
634 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
635 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
636 $data = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
637 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
638 $data['outputTableArray'] = $outputTableArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
639 $data['bookId'] = $bookId; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
640 $data['section_id'] = $section_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
641 $data['bookName'] = $bookName; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
642 $data['sectionName'] = $sectionName; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
643 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
644 return $data; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
645 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
646 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
647 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
648 // === for manage tag list === |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
649 public function EditTaglist($_postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
650 $query = "SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='taglist'"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
651 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
652 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
653 echo json_encode(mysql_error()); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
654 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
655 $row = mysql_fetch_assoc($result); |
51
840cdb52f476
add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
48
diff
changeset
|
656 $largest_id = $row['AUTO_INCREMENT']-1; |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
657 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
658 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
659 $topic_id = $_postdata['topic_id']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
660 $result = $this->GetTaglistByTopicID($topic_id); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
661 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
662 $taglistArray = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
663 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
664 foreach ($result as $row) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
665 $taglistArray[$row[0]] = array($row[1], $row[2], $row[3]); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
666 //$taglistArray[$row['id']] = array($row['name'], $row['tag'], $row['color']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
667 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
668 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
669 $topic_tag_name = $this->GetTopicTag($topic_id); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
670 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
671 $query = "SELECT id FROM taglist WHERE taglist.tag='".$topic_tag_name."'"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
672 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
673 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
674 echo json_encode(mysql_error()); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
675 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
676 $row = mysql_fetch_assoc($result); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
677 $topic_tag_id = $row['id']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
678 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
679 $data = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
680 $data['taglistArray'] = $taglistArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
681 $data['topic_id'] = $topic_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
682 $data['largest_id'] = $largest_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
683 $data['topic_tag_id'] = $topic_tag_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
684 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
685 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
686 return $data; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
687 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
688 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
689 |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
690 private function GetTag($_postdata) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
691 if (get_magic_quotes_gpc()) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
692 $id = stripslashes($_postdata['id']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
693 $name = stripslashes($_postdata['name']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
694 $tag = stripslashes($_postdata['tag']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
695 $color = stripslashes($_postdata['color']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
696 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
697 $id = $_postdata['id']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
698 $name = $_postdata['name']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
699 $tag = $_postdata['tag']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
700 $color = $_postdata['color']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
701 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
702 return array($id, $name, $tag, $color); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
703 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
704 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
705 public function NewTagElement($postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
706 if ($postdata['id']){ |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
707 list($id, $name, $tag, $color) = $this->GetTag($postdata); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
708 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
709 $query1 = sprintf("INSERT INTO `taglist` (`id`, `name`, `tag`, `color`, `systemName`) VALUES (%s, %s, %s, %s, %s)", |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
710 $this->GetSQLValueString($id, "int"), |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
711 $this->GetSQLValueString($name, "text"), |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
712 $this->GetSQLValueString($tag, "text"), |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
713 $this->GetSQLValueString($color, "text"), |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
714 $this->GetSQLValueString($this->systemNAME, "text")); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
715 $result1 = mysql_query($query1); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
716 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
717 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
718 // add it to topic_tag_relation table |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
719 $topic_id = $postdata['topic_id']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
720 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
721 // tag_id is $id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
722 $query = sprintf("INSERT INTO `topic_tag_relation` (`topic_id`,`tag_id`) VALUES (%s,%s)", $topic_id, $id); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
723 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
724 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
725 echo json_encode("error when insert into topic_tag_relation table"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
726 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
727 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
728 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
729 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
730 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
731 public function SaveTagElement($postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
732 if ($postdata['id']){ |
67
3ada9334ebfc
New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
66
diff
changeset
|
733 list($id, $name, $tag, $color) = $this->GetTag($postdata); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
734 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
735 $query = sprintf("UPDATE taglist SET `name`=%s, `tag`=%s, `color`=%s WHERE `id`=%s", |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
736 $this->GetSQLValueString($name, "text"), |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
737 $this->GetSQLValueString($tag, "text"), |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
738 $this->GetSQLValueString($color, "text"), |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
739 $this->GetSQLValueString($id, "int")); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
740 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
741 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
742 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
743 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
744 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
745 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
746 public function DeleteTag($postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
747 if ($postdata['id']) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
748 $queryInsert = sprintf("DELETE FROM `taglist` WHERE `id` = %s", stripslashes($postdata['id'])); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
749 $resultInsert = mysql_query($queryInsert); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
750 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
751 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
752 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
753 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
754 // === for config topic === |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
755 public function ConfigTagsInTopic($postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
756 $topic = $postdata['topic']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
757 $result = $this->GetTopicByID($topic); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
758 $row = mysql_fetch_assoc($result); |
65
f9ae94a9b041
New: adding topic names: name_en, name_ch, name_pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
63
diff
changeset
|
759 $topic_name_en = $row['name_en']; |
f9ae94a9b041
New: adding topic names: name_en, name_ch, name_pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
63
diff
changeset
|
760 $topic_name_ch = $row['name_ch']; |
f9ae94a9b041
New: adding topic names: name_en, name_ch, name_pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
63
diff
changeset
|
761 $topic_name_pinyin = $row['name_pinyin']; |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
762 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
763 /* |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
764 $query = "SELECT taglist.*, topic_tag_relation.topic_id FROM taglist LEFT JOIN topic_tag_relation ON taglist.id = topic_tag_relation.tag_id ORDER BY `topic_id`"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
765 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
766 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
767 return json_encode("Failed during selecting/joining taglist and topic_tag_relation table."); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
768 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
769 $taglistArray = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
770 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
771 array_push($taglistArray, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id']) ); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
772 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
773 */ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
774 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
775 // ------ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
776 $query = "SELECT taglist.*, topic_tag_relation.topic_id FROM taglist LEFT JOIN topic_tag_relation ON taglist.id = topic_tag_relation.tag_id ORDER BY `topic_id`"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
777 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
778 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
779 return json_encode("Failed during selecting/joining taglist and topic_tag_relation table."); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
780 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
781 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
782 $tag_intopic = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
783 $tag_others = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
784 $tag_tmp_others = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
785 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
786 if ($row['topic_id'] == $topic) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
787 array_push($tag_intopic, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id'])); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
788 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
789 array_push($tag_tmp_others, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id'])); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
790 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
791 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
792 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
793 // --- check if there's any duplicated tags in tag_tmp_others. remove the duplicated tags |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
794 $num_others = count($tag_tmp_others); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
795 for ($i=0; $i < $num_others; $i++) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
796 $cnt = 0; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
797 for ($j=$i+1; $j < $num_others; $j++) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
798 if ($tag_tmp_others[$i]['tag'] == $tag_tmp_others[$j]['tag']) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
799 break; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
800 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
801 $cnt++; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
802 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
803 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
804 if ($cnt == ($num_others-$i-1) ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
805 $row = $tag_tmp_others[$i]; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
806 array_push($tag_others, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id']) ); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
807 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
808 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
809 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
810 // --- remove duplicated tags in tag_others that is duplicated with tags in tag_intopic |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
811 $tag_tmp_others = $tag_others; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
812 $tag_others = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
813 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
814 foreach ($tag_tmp_others as $tmp) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
815 $cnt = 0; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
816 foreach ($tag_intopic as $intopic) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
817 if ($tmp['tag'] == $intopic['tag']) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
818 break; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
819 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
820 $cnt ++; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
821 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
822 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
823 if ($cnt == count($tag_intopic)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
824 // not appear in $tag_intopic |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
825 array_push($tag_others, $tmp); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
826 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
827 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
828 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
829 // ----- |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
830 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
831 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
832 $data = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
833 //$data['taglistArray'] = $taglistArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
834 $data['topic'] = $topic; |
65
f9ae94a9b041
New: adding topic names: name_en, name_ch, name_pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
63
diff
changeset
|
835 $data['topic_name'] = array('name_en'=>$topic_name_en,'name_ch'=>$topic_name_ch,'name_pinyin'=>$topic_name_pinyin); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
836 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
837 $data['tag_intopic'] = $tag_intopic; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
838 $data['tag_others'] = $tag_others; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
839 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
840 return $data; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
841 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
842 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
843 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
844 public function UpdateTagsInTopic($_postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
845 $topic_id = $_postdata['topic_id']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
846 $tag_ids = json_decode(str_replace('\\', '', $_postdata['ids'])); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
847 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
848 // update topic_tag_relation by tags_ids array as `tag_id` and topic_id as `topic_id` |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
849 // --- add new topic_tag_relation --- |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
850 foreach ($tag_ids as $tag_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
851 $query = "SELECT * FROM topic_tag_relation WHERE tag_id=".$tag_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
852 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
853 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
854 echo json_encode("error when select from topic_tag_relation"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
855 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
856 $topic_tag = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
857 $flag = false; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
858 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
859 if ($row['topic_id'] == $topic_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
860 $flag = true; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
861 break; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
862 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
863 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
864 if (!$flag) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
865 // insert a row into topic_tag_relation table |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
866 $queryUpdate = "INSERT INTO topic_tag_relation (topic_id, tag_id) VALUES (".$topic_id.",".$tag_id.")"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
867 $resultUpdate = mysql_query($queryUpdate); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
868 if (!$resultUpdate) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
869 return json_encode("error when insert topic_tag_relation table"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
870 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
871 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
872 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
873 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
874 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
875 // --- remove tags from this topic --- |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
876 $query = "SELECT * FROM topic_tag_relation WHERE topic_id=".$topic_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
877 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
878 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
879 echo json_encode("error when select from topic_tag_relation"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
880 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
881 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
882 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
883 $cnt = 0; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
884 foreach ($tag_ids as $tag_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
885 if ($row['tag_id'] == $tag_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
886 break; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
887 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
888 $cnt ++; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
889 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
890 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
891 $_id = $row['id']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
892 if ($cnt == count($tag_ids)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
893 // delete row with (topic_id, tag_ids) |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
894 $queryDelete = "DELETE FROM topic_tag_relation WHERE id=".$_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
895 $resultDelete = mysql_query($queryDelete); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
896 if (!$resultDelete) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
897 echo json_encode("error when delete from topic_tag_relation"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
898 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
899 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
900 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
901 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
902 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
903 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
904 /* |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
905 $query = "SELECT * FROM topic_tag_relation"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
906 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
907 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
908 echo json_encode("error when select from topic_tag_relation"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
909 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
910 $topic_tag = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
911 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
912 array_push($topic_tag, array('tag_id'=>$row['tag_id'], 'topic_id'=>$row['topic_id'])); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
913 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
914 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
915 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
916 foreach ($topic_tag as $value) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
917 $flag = false; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
918 foreach ($tag_ids as $tag_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
919 if ($value['tag_id'] == $tag_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
920 //update its topic_id to $topic_id |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
921 $queryUpdate = "UPDATE topic_tag_relation SET topic_id=".$topic_id." WHERE tag_id=".$tag_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
922 $resultUpdate = mysql_query($queryUpdate); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
923 if (!$resultUpdate) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
924 return json_encode("error when update topic_tag_relation table"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
925 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
926 $flag = true; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
927 break; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
928 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
929 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
930 if (!$flag && $value['topic_id'] == $topic_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
931 // set its topic_id to 0, indicating unsigned |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
932 $queryUpdate = "UPDATE topic_tag_relation SET topic_id=0 WHERE tag_id=".$value['tag_id']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
933 $resultUpdate = mysql_query($queryUpdate); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
934 if (!$resultUpdate) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
935 return json_encode("error when update topic_tag_relation table"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
936 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
937 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
938 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
939 */ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
940 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
941 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
942 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
943 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
944 private function GetTaglistByTopicID($topic_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
945 $taglistArray = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
946 // select taglist ids from topic_tag_relation table |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
947 $query = sprintf("SELECT * FROM `topic_tag_relation` WHERE `topic_id`='%s'", $topic_id); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
948 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
949 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
950 return json_encode("Failed during selecting topic_tag_relation table."); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
951 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
952 $taglist_ids = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
953 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
954 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
955 array_push($taglist_ids, $row['tag_id']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
956 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
957 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
958 // select taglist by tag ids |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
959 foreach ($taglist_ids as $tag_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
960 $query = sprintf("SELECT * FROM `taglist` WHERE `id`='%s'", $tag_id); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
961 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
962 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
963 echo mysql_error(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
964 return json_encode("Failed during selecting taglist table."); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
965 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
966 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
967 $row = mysql_fetch_assoc($result); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
968 array_push($taglistArray, array( $row['id'], $row['name'], $row['tag'], $row['color'] )); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
969 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
970 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
971 return $taglistArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
972 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
973 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
974 public function SetTopic($topic) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
975 $this->topic = $topic; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
976 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
977 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
978 public function GetTopic() { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
979 return $this->topic; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
980 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
981 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
982 private function GetTopiclistArray() { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
983 $topiclistArray = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
984 $result = $this->GetTopiclist(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
985 while ($row = mysql_fetch_assoc($result)) { |
65
f9ae94a9b041
New: adding topic names: name_en, name_ch, name_pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
63
diff
changeset
|
986 //array_push($topiclistArray, array('id'=>$row['id'],'name'=>$row['name'],'tag'=>$row['tag'])); |
f9ae94a9b041
New: adding topic names: name_en, name_ch, name_pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
63
diff
changeset
|
987 array_push($topiclistArray, array('id'=>$row['id'],'tag'=>$row['tag'],'name_en'=>$row['name_en'],'name_ch'=>$row['name_ch'],'name_pinyin'=>$row['name_pinyin'],)); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
988 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
989 return $topiclistArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
990 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
991 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
992 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
993 private function GetTopicTag($topic_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
994 $result = $this->GetTopicByID($topic_id); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
995 $row = mysql_fetch_assoc($result); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
996 $tag = $row['tag']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
997 return $tag; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
998 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
999 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1000 private function GetTopicName($topic_id) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1001 $result = $this->GetTopicByID($topic_id); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1002 $row = mysql_fetch_assoc($result); |
65
f9ae94a9b041
New: adding topic names: name_en, name_ch, name_pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
63
diff
changeset
|
1003 //$name = $row['name']; |
f9ae94a9b041
New: adding topic names: name_en, name_ch, name_pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
63
diff
changeset
|
1004 $name = array('name_en'=>$row['name_en'], 'name_ch'=>$row['name_ch'], 'name_pinyin'=>$row['name_pinyin']); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1005 return $name; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1006 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1007 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1008 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1009 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1010 // =========================== |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1011 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1012 // === for manage wordlist === |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1013 public function EditWordlist() { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1014 $result = $this->GetWordlist(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1015 $wordlistArray = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1016 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1017 $wordlistArray[$row['id']] = $row['name']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1018 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1019 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1020 $data = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1021 $data['wordlistArray'] = $wordlistArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1022 return $data; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1023 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1024 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1025 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1026 public function AddNewList($postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1027 if ($postdata['text']){ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1028 if (get_magic_quotes_gpc()) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1029 $name = stripslashes($postdata['text']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1030 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1031 $name = $postdata['text']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1032 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1033 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1034 $query1 = sprintf("INSERT INTO `wordlist` (`name`, `systemName`) VALUES (%s, %s)", |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1035 $this->GetSQLValueString($name, "text"), |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1036 $this->GetSQLValueString($this->systemNAME, "text")); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1037 $result1 = mysql_query($query1); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1038 file_put_contents( "data/wordlist/".mysql_insert_id().".txt", "(empty now)"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1039 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1040 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1041 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1042 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1043 public function SaveWordlist($postdata) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1044 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1045 if ($postdata['text']){ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1046 $date = date('Y_m_d_H_i_s', time()); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1047 if ( file_exists("data/wordlist/".$postdata['filename'].".txt") ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1048 $filename = "data/wordlist/".$postdata['filename']."_".$date.".txt"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1049 $oldFile = file_get_contents("data/wordlist/".$postdata['filename'].".txt"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1050 file_put_contents($filename, $oldFile); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1051 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1052 /*else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1053 $filename = "data/wordlist/".$postdata['filename'].".txt"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1054 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1055 */ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1056 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1057 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1058 if (get_magic_quotes_gpc()) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1059 $require = stripslashes($postdata['text']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1060 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1061 $require = $postdata['text']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1062 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1063 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1064 $require = preg_replace("/<br>/u", "<br>", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1065 file_put_contents("data/wordlist/".$postdata['filename'].".txt", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1066 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1067 /* |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1068 if ($postdata['text']){ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1069 $date = date('Y_m_d_H_i_s', time()); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1070 if ( file_exists("data/wordlist/".$postdata['filename'].".txt") ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1071 $oldFile = file_get_contents("data/wordlist/".$postdata['filename'].".txt"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1072 file_put_contents("data/wordlist/".$postdata['filename']."_".$date.".txt", $oldFile); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1073 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1074 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1075 if (get_magic_quotes_gpc()) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1076 $require = stripslashes($postdata['text']); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1077 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1078 $require = $postdata['text']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1079 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1080 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1081 // $require = preg_replace("/<br>/u", "", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1082 file_put_contents("data/wordlist/".$postdata['filename'].".txt", $require); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1083 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1084 */ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1085 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1086 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1087 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1088 // ======================================= |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1089 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1090 public function sortFunction($a,$b) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1091 return strlen($b)-strlen($a); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1092 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1093 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1094 private function GetSectionId() { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1095 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1096 if (is_numeric($this->section_id)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1097 return $this->section_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1098 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1099 return json_encode("Error: No section id"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1100 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1101 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1102 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1103 private function GetSectionInfo() { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1104 $section_id = $this->GetSectionId(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1105 if (!is_numeric($section_id)){ |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1106 return $section_id; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1107 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1108 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1109 $result = $this->GetSectionsByID($section_id); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1110 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1111 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1112 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1113 $bookId=$row['books_id']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1114 $startPage=$row['start_page']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1115 $endPage=$row['end_page']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1116 $sectionName = $row['name']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1117 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1118 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1119 $data = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1120 $data['bookId'] = $bookId; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1121 $data['startPage'] = $startPage; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1122 $data['endPage'] = $endPage; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1123 $data['sectionName'] = $sectionName; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1124 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1125 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1126 return $data; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1127 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1128 |
74
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
1129 private function ParseDataInFile($filename) { |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1130 $text = file_get_contents($filename); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1131 $xml = simplexml_load_string($text); //or die("Error: Cannot load from xml string"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1132 if (!$xml) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1133 // when file created by section_id, read the plain text from file_get_contents |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1134 return $text; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1135 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1136 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1137 $this->topic = (string)$xml->topic; // set topic id |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1138 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1139 // get taglist in file |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1140 $taglist_infile = $xml->tagitem; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1141 $taglistArray = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1142 foreach ($taglist_infile as $row) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1143 array_push($taglistArray, array((string)$row->id,(string)$row->name,(string)$row->tag,(string)$row->color )); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1144 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1145 if ($taglistArray) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1146 $this->taglist_infile = $taglistArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1147 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1148 |
74
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
1149 // --- get book meta data from file, replaced by SetBookMetaDataBySectionId(), which retrives book meta data from LGService |
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
1150 /* |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1151 $book_meta = $xml->book; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1152 $book_metaArray = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1153 foreach ($book_meta as $row) { |
69
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
1154 array_push($book_metaArray, array((string)$row->id,(string)$row->name,(string)$row->level1,(string)$row->level2, |
70
359f48d58cbc
New: hover on regex elem
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
69
diff
changeset
|
1155 (string)$row->period,(string)$row->dynasty,(string)$row->start_year,(string)$row->end_year,(string)$row->line, |
69
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
1156 (string)$row->volume,(string)$row->author,(string)$row->edition,(string)$row->in_jibengujiku,(string)$row->admin_type )); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1157 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1158 if ($book_metaArray) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1159 $this->book_meta = $book_metaArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1160 } |
74
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
1161 */ |
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
1162 // ----- |
54
f9e7119339b2
bug fixed: when addTagTitle, removing self-closing tag which causes error in coloring tag
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
53
diff
changeset
|
1163 |
f9e7119339b2
bug fixed: when addTagTitle, removing self-closing tag which causes error in coloring tag
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
53
diff
changeset
|
1164 $contentString = (string)($xml->text_content->asXML()); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1165 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1166 return $contentString; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1167 } |
74
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
1168 |
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
1169 |
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
1170 private function GetSectionContent() { // called only by GetTextFromLocal() |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1171 $section_id = $this->GetSectionId(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1172 $section_info = $this->GetSectionInfo(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1173 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1174 $bookId = $section_info['bookId']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1175 $startPage = $section_info['startPage']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1176 $endPage = $section_info['endPage']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1177 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1178 $contentString=""; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1179 $data_path = $this->GetDataPath(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1180 if ( file_exists($data_path."parsing_files/".$section_id.".txt") ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1181 $filename = $data_path."parsing_files/".$section_id.".txt"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1182 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1183 // --- parsing meta data |
74
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
1184 $stringInput = $this->ParseDataInFile($filename); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1185 // ---- |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1186 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1187 // if the text is from file system |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1188 $stringInput = preg_replace("/ /u", "○", $stringInput); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1189 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1190 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); |
63
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
1191 |
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
1192 $this->branch_id = 1; // testing at local |
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
1193 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1194 } else { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1195 $query = sprintf("SELECT `content`, `line`, `books_id` FROM `contents` WHERE `books_id`=\"%s\" AND `line`>=%d AND `line`<=%d", $bookId, $startPage, $endPage); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1196 $result = mysql_query($query); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1197 if (!$result) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1198 return json_encode("Failed during selecting content table."); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1199 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1200 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1201 $contentString.="【".$row['line']."】".$row['content']."\n"; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1202 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1203 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1204 // the text is from database |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1205 $stringInput = $contentString; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1206 $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1207 $stringInput = preg_replace("/ /u", "○", $stringInput); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1208 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1209 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1210 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1211 |
69
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
1212 /* |
74
60b5a94163c3
New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
73
diff
changeset
|
1213 // get book_meta from books table in db on localhost |
51
840cdb52f476
add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
48
diff
changeset
|
1214 $book_meta = array(); |
840cdb52f476
add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
48
diff
changeset
|
1215 $books_result = $this->GetBooksByID($bookId); |
840cdb52f476
add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
48
diff
changeset
|
1216 while ($row = mysql_fetch_assoc($books_result)) { |
63
3395385476d1
bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
62
diff
changeset
|
1217 array_push($book_meta, array($row['id'],$row['name'],$row['author'],(string)$row['start_year'],(string)$row['line'],(string)$row['dynasty'])); |
51
840cdb52f476
add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
48
diff
changeset
|
1218 // use 'start_year' as year, 'line' is pagenumber |
840cdb52f476
add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
48
diff
changeset
|
1219 } |
69
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
1220 $this->book_meta = $book_meta; |
edb8a2e8ce84
New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
67
diff
changeset
|
1221 */ |
51
840cdb52f476
add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
48
diff
changeset
|
1222 |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1223 return $stringInput; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1224 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1225 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1226 private function GetDataPath() { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1227 return getcwd()."/data/"; // get the current file path, which is getcwd(), and concatenate with "/data/" |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1228 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1229 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1230 private function GetTaglistArray() { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1231 $taglistArray = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1232 $result = $this->GetTaglist(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1233 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1234 array_push($taglistArray, array( $row['id'], $row['name'], $row['tag'], $row['color'] )); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1235 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1236 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1237 return $taglistArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1238 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1239 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1240 private function GetWordlistArray() { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1241 $wordlistArray=""; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1242 $result = $this->GetWordlist(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1243 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1244 $listString = file_get_contents("data/wordlist/".$row['id'].".txt"); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1245 $listString = preg_replace("/<div>/u", "\n", $listString); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1246 $listString = preg_replace("/<\/div>/u", "", $listString); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1247 $listString = preg_replace("/<span(.*?)>/u", "", $listString); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1248 $listString = preg_replace("/<\/span>/u", "", $listString); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1249 //$listString = preg_replace("/\n/u", "|", $listString); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1250 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1251 $wordlistArray2 = explode( "\n", $listString ); |
71
26d8c4c43d86
minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
70
diff
changeset
|
1252 //usort($wordlistArray2,'sortFunction'); |
47
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1253 foreach ( $wordlistArray2 as $index=>$value ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1254 $wordlistArray2[$index] = implode("○?", preg_split("/(?<!^)(?!$)/u", $value)); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1255 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1256 foreach ( $wordlistArray2 as $index=>$value ) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1257 if ($value=="") unset($wordlistArray2[$index]); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1258 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1259 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1260 $listString = implode("|", $wordlistArray2); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1261 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1262 if ( $listString[0]=="|" ) $listString = substr($listString, 1); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1263 $wordlistArray[] = array( $row['id'], $row['name'], $listString ); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1264 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1265 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1266 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1267 return $wordlistArray; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1268 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1269 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1270 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1271 protected function GetBooksInfo($bookId) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1272 $result = $this->GetSectionsByID($bookId); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1273 while ($row = mysql_fetch_assoc($result)) { |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1274 $bookName = $row['name']; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1275 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1276 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1277 $data = array(); |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1278 $data['bookName'] = $bookName; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1279 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1280 return $data; |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1281 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1282 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1283 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1284 } |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1285 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1286 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1287 |
886f43b26ee2
move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1288 ?> |