annotate models/extractapp.php @ 86:0141df465205 extractapp_dev

New: add chinese characters to pinyin
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 30 Apr 2015 10:52:05 +0200
parents ecc4b22e9b05
children fb5049fc5dd7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1 <?php
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
2 /*
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
3 * extractapp.php
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
4 * This file is part of Extraction-interface.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
5 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
6 * Extraction-interface is free software: you can redistribute it and/or modify
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
7 * it under the terms of the GNU General Public License as published by
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
8 * the Free Software Foundation, either version 3 of the License, or
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
9 * (at your option) any later version.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
10 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
11 * Extraction-interface is distributed in the hope that it will be useful,
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
14 * GNU General Public License for more details.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
15 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
16 * You should have received a copy of the GNU General Public License
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
17 * along with Extraction-interface. If not, see <http://www.gnu.org/licenses/>.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
18 */
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
19 /**
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
20 * ExtractappModel class is extended from the BaseModel class.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
21 * This is where we implement the functions/models to prepare data that been sent to views.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
22 * ExtractappModel is notified by Extractapp controller when there has been a change in its state,
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
23 * and produces the output/data to the corresponding view in "views/Extractapp/".
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
24 *
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
25 */
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
26
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
27 class ExtractappModel extends BaseModel{
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
28
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
29 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
30 $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
31 public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>"");
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
32
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
33
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
34 public function SetTextFromFileId() { // remove $_postdata as input
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
35 /**
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
36 * Get text content from LGService by $this->file_id.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
37 * After preprocessing the text string (replace space to circle symbol, link for page number, etc),
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
38 * set $this->lg_text to the processed text gotten from LGService.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
39 */
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
40
53
f9594c240826 get/update text after saving, for xml file consistency
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 52
diff changeset
41 /*
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
42 $this->file_id = $_postdata['fileId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
43 $branch_id = $_postdata['branchId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
44 $section_id = $_postdata['sectionId'];
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 $this->branch_id = $branch_id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
47 $this->user_id = $_postdata['userId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
48 $this->section_id = $section_id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
49
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
50 $this->section_name = $_postdata['sectionName'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
51 $this->book_id = $_postdata['bookId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
52 $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
53 */
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
54
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
55 // get from URL with file_id
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
56 $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
57 //$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
58 // --- 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
59 $lg_text = $this->ParseDataInFile($lg_text_url);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
60
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
61
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
62 $stringInput = $lg_text;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
63 $stringInput = preg_replace("/ /u", "○", $stringInput);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
64 $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
65 $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
66 $lg_text = $stringInput;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
67
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
68 $this->lg_text = $lg_text;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
69
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
70 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
71
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
72 public function SetBookMetadataBySectionId() {
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
73
69
edb8a2e8ce84 New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 67
diff changeset
74 // 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
75 $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
76 $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
77
69
edb8a2e8ce84 New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 67
diff changeset
78 $b = $section_meta['section']['book'];
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
79
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
80 $this->book_name = $b['name'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
81 $this->book_id = $b['id'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
82 /*
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
83 $book_meta = array();
69
edb8a2e8ce84 New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 67
diff changeset
84 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
85 $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
86 $b['volume'],$b['author'], $b['edition'],$b['in_jibengujiku'], $b['admin_type'])); // missing author,year,pagenumber
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
87 */
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
88 /*
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
89 $book_meta = array('id'=>$b['id'],'name'=>$b['name'],'level1'=>$b['level1'],'level2'=>$b['level2'],
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
90 'period'=>$b['period'],'dynasty'=>$b['dynasty'],'start_year'=>$b['start_year'], 'end_year'=>$b['end_year'],'line'=>$b['line'],
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
91 'volume'=>$b['volume'],'author'=>$b['author'],'edition'=>$b['edition'],
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
92 'in_jibengujiku'=>$b['in_jibengujiku'],'admin_type'=>$b['admin_type']); // missing author,year,pagenumber
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
93 */
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
94
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
95 $book_meta->id = $b['id'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
96 $book_meta->name = $b['name'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
97 $book_meta->level1 = $b['level1'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
98 $book_meta->level2 = $b['level2'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
99 $book_meta->period = $b['period'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
100 $book_meta->dynasty = $b['dynasty'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
101 $book_meta->start_year = $b['start_year'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
102 $book_meta->end_year = $b['end_year'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
103 $book_meta->line = $b['line'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
104 $book_meta->volume = $b['volume'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
105 $book_meta->author = $b['author'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
106 $book_meta->edition = $b['edition'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
107 $book_meta->in_jibengujiku = $b['in_jibengujiku'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
108 $book_meta->admin_type = $b['admin_type'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
109
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
110
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
111 $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
112
3395385476d1 bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 62
diff changeset
113 }
3395385476d1 bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 62
diff changeset
114
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
115 public function SetTextFromSectionId() { // remove $_postdata as input
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
116 /**
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
117 * Get text content from LGService by $this->section_id.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
118 * After preprocessing the text string (replace space to circle symbol, link for page number, etc),
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
119 * set $this->lg_text to the processed text gotten from LGService.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
120 */
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
121
53
f9594c240826 get/update text after saving, for xml file consistency
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 52
diff changeset
122 /*
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
123 $section_id = $_postdata['sectionId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
124 $this->section_id = $section_id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
125 $this->user_id = $_postdata['userId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
126
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
127 $this->section_name = $_postdata['sectionName'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
128 $this->book_id = $_postdata['bookId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
129 $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
130 */
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
131
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
132 // 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
133 // $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
134 $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
135 $lg_text = file_get_contents($lg_text_url);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
136
51
840cdb52f476 add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 48
diff changeset
137
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
138 $stringInput = $lg_text;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
139 $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
140 $stringInput = preg_replace("/ /u", "○", $stringInput);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
141 $stringInput = preg_replace("/\n/u", "<br>", $stringInput);
73
2daef8e36214 minor modification
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 71
diff changeset
142 $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
143 $lg_text = $stringInput;
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 $this->lg_text = $lg_text;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
146 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
147
74
60b5a94163c3 New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 73
diff changeset
148 // This is only used on localhost
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
149 public function SetTextFromLocal($_id){
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
150 $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
151 //$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
152 $this->messages['debug'] .= "[Debug] from my local"."<br>";
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
153 $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
154 }
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
155
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
156
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
157 public function SetInfoFromPreviousPage($_postdata) {
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
158 /**
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
159 * Get information from post data passsed by the previous page, and set variables in $this.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
160 * The previous page could be:
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
161 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
162 * (1) LGService: the first time user enters Extraction-interface, which should linked from LGService.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
163 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
164 * (2) Extraction-interface itself: changing topic then continue to tag, saving text to LGService, reload the text from LGService.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
165 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
166 */
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
167
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
168 if (isset($_postdata['fileId'])) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
169 $this->file_id = $_postdata['fileId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
170 }
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
171 if (isset($_postdata['sectionId'])) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
172 $this->section_id = $_postdata['sectionId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
173 }
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
174 if (isset($_postdata['text'])) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
175 $this->lg_text = $_postdata['text'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
176 }
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
177 if (isset($_postdata['branchId'])) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
178 $this->branch_id = $_postdata['branchId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
179 }
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
180 if (isset($_postdata['userId'])) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
181 $this->user_id = $_postdata['userId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
182 }
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
183 if (isset($_postdata['topic_id'])) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
184 $this->topic = $_postdata['topic_id'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
185 }
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
186 if (isset($_postdata['sectionName'])) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
187 $this->section_name = $_postdata['sectionName'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
188 }
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
189 if (isset($_postdata['bookName'])) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
190 $this->book_name = $_postdata['bookName'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
191 }
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
192 if (isset($_postdata['bookId'])) {
83
7b05275b7a70 book_id as string in postdata
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 82
diff changeset
193 $this->book_id = $_postdata['bookId'];
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
194 }
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
195 if (isset($_postdata['currentFileId'])) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
196 $this->current_fileId = $_postdata['currentFileId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
197 }
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
198 if (isset($_postdata['taglistArray'])) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
199 $this->taglist_infile = json_decode($_postdata['taglistArray']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
200 }
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
201 if (isset($_postdata['book_meta'])) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
202 $this->book_meta = json_decode($_postdata['book_meta']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
203 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
204
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
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
207
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
208 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
209 // 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
210 $cnt_list1 = count($list1);
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
211 $cnt_list2 = count($list2);
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
212
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
213 if ($cnt_list1 > $cnt_list2) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
214 return false;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
215 }
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
216 foreach ($list1 as $v1) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
217 $cnt = 0;
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
218 foreach ($list2 as $v2) {
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
219 $num_field = count($v2);
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
220 $matched = true;
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
221 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
222 if ($v1[$i] != $v2[$i]) {
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
223 $matched = false;
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
224 break;
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
225 }
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
226 }
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
227
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
228 if (!$matched) {
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
229 // not match with this v2
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
230 $cnt += 1;
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
231 } else {
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
232 break;
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
233 }
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
234
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
235 }
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
236 if ($cnt == $cnt_list2) {
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
237 return false;
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
238 }
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 return true;
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
241
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
242 }
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
243
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
244 // === for tagging ===
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
245 public function StartTagging() {
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
246 /**
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
247 * This is the main method for tagging text. It passes all the information to "views/Extractapp/TaggingText.php" view.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
248 * The information contain the text string, taglist array, wordlis array, topic, etc.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
249 */
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
250
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
251 $section_id = $this->section_id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
252 $stringInput = $this->lg_text;
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 $data = array(); // data array to be passed to view
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
255
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
256 //$taglistArray = $this->GetTaglistArray();
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
257 //for GetTaglistByTopicId:
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
258 $taglistArray = $this->GetTaglistByTopicId($this->GetTopic());
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
259
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
260 // $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
261 // $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
262 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
263 $this->taglist_infile = "";
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
264 }
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
265 $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
266
47
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 // book_meta
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
269 $data['book_meta'] = $this->book_meta;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
270
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
271 // topic list
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
272 $topiclistArray = $this->GetTopiclistArray();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
273
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
274
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
275 $wordlistArray = $this->GetWordlistArray();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
276
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
277 $data['stringInput'] = $stringInput;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
278 $data['taglistArray'] = $taglistArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
279 $data['wordlistArray'] = $wordlistArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
280 $data['section_id'] = $section_id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
281 $data['topiclistArray'] = $topiclistArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
282 $data['default_topic_id'] = $this->GetTopic();
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
283 $topic_id = $this->GetTopic();
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
284
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
285 $data['topic_tag'] = $this->GetTopicTag($topic_id);
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
286 $data['topic_name'] = $this->GetTopicName($topic_id);
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
287 $data['topic_tag_ch'] = $this->GetTopicTagName($topic_id);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
288
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
289
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
290 $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
291 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id,
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
292 'book_name'=>$this->book_name,'section_name'=>$this->section_name, 'period'=>$this->book_meta->period,
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
293 'current_fileId'=>$this->current_fileId);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
294
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
295 $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
296 $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
297 $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
298 $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
299 $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
300
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
301 $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
302 $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
303 $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
304 $this->messages['info'] .= ", file id: ".$this->file_id;
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
305 $this->messages['info'] .= ", period: ".$this->book_meta->period;
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
306 $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
307
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
308
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
309 $data['messages'] = $this->messages;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
310
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
311 return $data;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
312
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
313 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
314
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
315 public function SaveFullText($postdata) {
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
316 // locally
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
317 if ($postdata['text']){
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
318 $date = date('Y_m_d_H_i_s', time());
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
319 if ( file_exists("data/parsing_files/".$postdata['filename'].".txt") ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
320 $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
321 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
322 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
323
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
324 if (get_magic_quotes_gpc()) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
325 $require = stripslashes($postdata['text']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
326 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
327 $require = $postdata['text'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
328 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
329
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
330 $require = preg_replace("/【<a(.*?)>(.*?)<\/a>】/u", "【\\2】", $require);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
331 $require = preg_replace('/&amp;/u', "&", $require);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
332 $require = preg_replace("/○/u", " ", $require);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
333 $require = preg_replace("/<br>/u", "\n", $require);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
334 $require = preg_replace("/<br>/u", "\n", $require);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
335 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
336 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
337
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
338 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
339
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
340 public function UpdateInfoResponsedFromLGService($response) {
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
341 /**
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
342 *
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
343 */
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
344
73
2daef8e36214 minor modification
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 71
diff changeset
345 if (isset($response["file"])) {
2daef8e36214 minor modification
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 71
diff changeset
346 $response_file = $response["file"];
2daef8e36214 minor modification
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 71
diff changeset
347 }
2daef8e36214 minor modification
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 71
diff changeset
348 if (isset($response["branch"])) {
2daef8e36214 minor modification
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 71
diff changeset
349 $response_branch = $response["branch"];
2daef8e36214 minor modification
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 71
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 $status = (string)$response["status"];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
353 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
354 $this->messages['info'] .= "[Info] Saving success. <br>";
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
355 $this->file_id = (string)$response_file["id"];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
356 $this->branch_id = (string)$response_branch["id"];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
357
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
358 } else if ($status == "error") {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
359 // 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
360 $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
361 $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
362
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
363 $response_currentFile = $response["currentFile"];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
364 $this->current_fileId = (string)$response_currentFile["id"];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
365
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
366 }
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 }
57
5cf9720a2e25 New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 56
diff changeset
370
5cf9720a2e25 New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 56
diff changeset
371 public function ReloadSetting() {
5cf9720a2e25 New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 56
diff changeset
372 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
373 $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
374 $this->current_fileId = 0;
5cf9720a2e25 New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 56
diff changeset
375 }
5cf9720a2e25 New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 56
diff changeset
376 }
5cf9720a2e25 New: add reloadText to load the latest version
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 56
diff changeset
377
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
378 // This is only called by SaveFullTextToLGService()
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
379 private function AppendMetadata($text_content) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
380 $text = '<?xml version="1.0" encoding="UTF-8"?>';
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
381 $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
382 // --- topic ---
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
383 $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
384 // --- book meta data ---
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
385 $book = $this->book_meta;
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
386
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
387 $text .= "<book>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
388 $text .= "<id>".$book->id."</id>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
389 $text .= "<name>".$book->name."</name>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
390 $text .= "<level1>".$book->level1."</level1>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
391 $text .= "<level2>".$book->level2."</level2>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
392 $text .= "<period>".$book->period."</period>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
393 $text .= "<dynasty>".$book->dynasty."</dynasty>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
394 $text .= "<start_year>".$book->start_year."</start_year>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
395 $text .= "<end_year>".$book->end_year."</end_year>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
396 $text .= "<line>".$book->line."</line>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
397 $text .= "<volume>".$book->volume."</volume>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
398 $text .= "<author>".$book->author."</author>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
399 $text .= "<edition>".$book->edition."</edition>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
400 $text .= "<in_jibengujiku>".$book->in_jibengujiku."</in_jibengujiku>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
401 $text .= "<admin_type>".$book->admin_type."</admin_type>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
402 $text .= "</book>\n";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
403
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
404
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
405 /*
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
406 foreach ($book as $b) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
407 $text .= "<book>\n";
51
840cdb52f476 add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 48
diff changeset
408 $text .= "<id>".$b[0]."</id>\n";
840cdb52f476 add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 48
diff changeset
409 $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
410 $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
411 $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
412 $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
413 $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
414 $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
415 $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
416 $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
417 $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
418 $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
419 $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
420 $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
421 $text .= "<admin_type>".$b[13]."</admin_type>\n";
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
422 $text .= "</book>\n";
69
edb8a2e8ce84 New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 67
diff changeset
423
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
424 }
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
425 */
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
426
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
427 // --- section info ---
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
428 $text .= "<section>\n";
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
429 $text .= "<id>".$this->section_id."</id>\n";
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
430 $text .= "<name>".$this->section_name."</name>\n";
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
431 $text .= "</section>\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
432
75233b09c580 saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 74
diff changeset
433 // ---- 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
434 // $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
435 // obtain the latest taglist from db
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
436 $taglist = $this->GetTaglistByTopicId($this->GetTopic());
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
437
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
438 foreach ($taglist as $tagitem) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
439 $text .= "<tagitem>\n";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
440 $text .= "<id>".$tagitem[0]."</id>\n";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
441 $text .= "<name>".$tagitem[1]."</name>\n";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
442 $text .= "<tag>".$tagitem[2]."</tag>\n";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
443 $text .= "<color>".$tagitem[3]."</color>\n";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
444 $text .= "</tagitem>\n";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
445 }
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
446 // ----
75233b09c580 saving latest taglist from db according to topic (even when changing topic)
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 74
diff changeset
447 // --- text_content ---
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
448 $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
449 $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
450 // ----
47
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 return $text;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
453 }
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
454
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
455 public function SaveFullTextToLGService($_postdata) {
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
456 /**
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
457 * It saves the full tagged text string in postdata to LGService.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
458 * The responses returned by LGService will later be handled in
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
459 */
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
460
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
461 // --------
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
462 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
463
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
464 if ($_postdata['text']){
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
465 $date = date('Y_m_d_H_i_s', time());
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
466 if ( file_exists("data/parsing_files/".$_postdata['sectionId'].".txt") ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
467 $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
468 //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
469 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
470 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
471 }
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
472 }
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 if (get_magic_quotes_gpc()) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
475 $require = stripslashes($_postdata['text']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
476 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
477 $require = $_postdata['text'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
478 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
479
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
480 $require = preg_replace("/【<a(.*?)>(.*?)<\/a>】/u", "【\\2】", $require);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
481 $require = preg_replace('/&amp;/u', "&", $require);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
482 $require = preg_replace("/○/u", " ", $require);
79
e6e213b26454 Bug fixed: file crashed after saving (preg_replace remove unnecessary symbols within br tag
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 78
diff changeset
483 $require = preg_replace("/<br(.*?)>/u", "\n", $require);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
484 //$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
485
76
c49192885290 Bug fixed: ambiguous tag occured at Editing-text mode
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 75
diff changeset
486 $require = "<text_content>".$require."</text_content>\n";
c49192885290 Bug fixed: ambiguous tag occured at Editing-text mode
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 75
diff changeset
487
c49192885290 Bug fixed: ambiguous tag occured at Editing-text mode
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 75
diff changeset
488 /*
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
489 if ($_postdata['branchId'] == 0) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
490 // -- 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
491 $require = "<text_content>".$require."</text_content>\n";
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
492 }
76
c49192885290 Bug fixed: ambiguous tag occured at Editing-text mode
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 75
diff changeset
493 */
c49192885290 Bug fixed: ambiguous tag occured at Editing-text mode
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 75
diff changeset
494
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
495 $require = $this->AppendMetadata($require);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
496
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
497 //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
498 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
499 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
500 }
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
501 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
502
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
503 // ------
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
504
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 if ($_postdata['branchId'] != 0) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
507 // -- exiting branch case
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
508 $postfields = array(
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
509 "text" => $require,
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
510 "branchId" => $_postdata['branchId'],
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
511 "userId" => $_postdata['userId'],
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
512 "userPreviousFileId" => $_postdata['fileId'],
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 $save_url = $this->save_to_LGService_url;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
515
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
516 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
517 // -- 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
518 // echo "saveNew!";
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
519 $user_id = "0";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
520 if ($_postdata['userId']) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
521 $user_id = $_postdata['userId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
522 }
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 $postfields = array(
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
525 "text" => $require,
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
526 "sectionId" => $_postdata['sectionId'],
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
527 "userId" => $user_id,
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
528 "label" => $_postdata['label'],
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 $save_url = $this->save_new_to_LGService_url;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
531 }
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
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
534 // set up the curl resource
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
535 $ch = curl_init();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
536 curl_setopt($ch, CURLOPT_URL, $save_url);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
537 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
538 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
539 curl_setopt($ch, CURLOPT_POST, true);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
540 curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
541 //curl_setopt($ch, CURLOPT_HEADER, true);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
542 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
543 'Content-type: multipart/form-data;charset=utf-8'
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
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
546 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
547 // 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
548 $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
549 }
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
550
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
551
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
552 // output the profile information - includes the header
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
553 //echo($output) . PHP_EOL;
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 // close curl resource to free up system resources
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
556 curl_close($ch);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
557
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
558 $response = json_decode($output, true);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
559 return $response;
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 }
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 // --- for regex ----
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
564 private function GetRegexFilenameById($topic_id) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
565 $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
566 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
567 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
568 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
569 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
570
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
571 $filenames = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
572 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
573 array_push($filenames, $row['regex_filename']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
574 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
575
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
576 return $filenames;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
577 }
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
578 public function LoadSmartRegex($topic_id) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
579
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
580 // 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
581 $filenames = $this->GetRegexFilenameById($topic_id);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
582
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
583 // Get regex file from filesystem ----
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
584 $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
585 $returnArray = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
586 $files1 = scandir($data_path."regex_files");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
587 foreach ( $files1 as $file ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
588 if ( $file != "." && $file != ".." && $file != ".DS_Store") {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
589 foreach ($filenames as $filename) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
590 if ($file == $filename) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
591 $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
592 break;
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 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
595 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
596 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
597 echo json_encode($returnArray);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
598 return;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
599 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
600
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
601
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
602 public function SaveSmartRegex($_postdata) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
603 if ($_postdata['text']){
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 // --- update topic_regex_relation table ---
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
606 $topic_id = $_postdata['topic_id'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
607 $filename = $_postdata['filename'].'.txt';
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
608
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
609 // 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
610 $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
611 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
612 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
613 echo json_encode("ErrorDB");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
614 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
615 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
616 if ($row && !$_postdata['forcesave']) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
617 // promt user a comfirm to force saving or not
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
618 echo json_encode("ForceSave");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
619 return;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
620 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
621 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
622
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 if (!$_postdata['forcesave']) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
625 $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
626 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
627 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
628 echo json_encode("ErrorDB");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
629 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
630 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
631 // --- write to filesystem ---
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 $date = date('Y_m_d_H_i_s', time());
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
635 if ( file_exists("regex_files/".$_POST['filename'].".txt") ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
636 $oldFile = file_get_contents("regex_files/".$_POST['filename'].".txt");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
637 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
638 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
639 */
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
640 $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
641
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
642 if (get_magic_quotes_gpc()) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
643 $require = stripslashes($_postdata['text']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
644 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
645 $require = $_postdata['text'];
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 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
649
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
650
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
651 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
652 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
653
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
654
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
655 private function GetTableArray($_taglistArray, $_topic_tag, $_content) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
656
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
657 $outputTableArray = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
658 $outputTableArray[0]=array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
659 $outputTableArray[0][0]=array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
660 $outputTableArray[0][1]=array();
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
661 foreach ( $_taglistArray as $value ) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
662 $outputTableArray[0][0][$value[2]] = $value[1];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
663 $outputTableArray[0][1][$value[2]] = $value[1]."(Title)";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
664 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
665 $outputTableArray[0]["other"] = "其他";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
666 $outputTableArray[0]["page"] = "頁數";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
667 $outputTableArray[0]["full"] = "全文";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
668
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
669 // id, name, tag, color in _taglistArray
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
670 foreach ( $_taglistArray as $tagValue ) {
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
671 $tag_name = $tagValue[2]; // $tagValue[2] is tag_name
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
672 $content = preg_replace("/<\/".$tag_name.">○*<".$tag_name.">/u", "", $_content);
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
673 $content = preg_replace("/<".$tag_name.">[ ]*<\/".$tag_name.">/u", "", $_content);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
674 }
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 $contentLineArray = explode( "<br>", $content );
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
677
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
678 $count=0;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
679 $pageNow=NULL;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
680 foreach ( $contentLineArray as $value ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
681 $count++;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
682 $recordString = $value;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
683 $otherString = $recordString;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
684 //echo $recordString."<br>\n";
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
685 // find hyper link in pattern with <a>...</a>
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
686 if ( preg_match("/【<a(.*?)>(.*?)<\/a>】/u", $recordString, $matches) ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
687 $pageNow = $matches[2];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
688 }
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
689 foreach ( $_taglistArray as $tagValue ) {
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
690 $tag_name = $tagValue[2]; // $tagValue[2] is tag_name
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
691
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
692 if ( preg_match_all("/<".$tag_name.">(.*?)<\/".$tag_name.">/u", $recordString, $matches, PREG_SET_ORDER) ) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
693 foreach ( $matches as $matchesValue ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
694 $matchesValue[1] = preg_replace("/○/u", "", $matchesValue[1]);
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
695
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
696 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
697 foreach ( $matches2 as $matches2Value ) {
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
698 if ( isset($outputTableArray[$count][0][$tag_name]) ) {
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
699 $outputTableArray[$count][0][$tag_name] .= ";".$matches2Value[1];
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
700 } else {
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
701 $outputTableArray[$count][0][$tag_name] = $matches2Value[1];
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
702 }
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 } else {
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
705 if ( isset($outputTableArray[$count][0][$tag_name]) ) {
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
706 $outputTableArray[$count][0][$tag_name] .= ";".$matchesValue[1];
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
707 } else {
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
708 $outputTableArray[$count][0][$tag_name] = $matchesValue[1];
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
709 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
710 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
711 }
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
712 $otherString = preg_replace("/<".$tag_name.">(.*?)<\/".$tag_name.">/u", " ", $otherString);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
713 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
714 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
715 $otherString = preg_replace("/○/u", "", $otherString);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
716 $outputTableArray[$count]["other"] = $otherString;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
717 $outputTableArray[$count]["page"] = $pageNow;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
718 $value = preg_replace("/>/u", "&gt;", $value);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
719 $value = preg_replace("/</u", "&lt;", $value);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
720 $outputTableArray[$count]["full"] = $value;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
721 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
722
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
723
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
724
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
725 foreach ( $outputTableArray as $arrayIndex => $arrayValue ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
726 // output each row which the topic tag
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
727 // e.g. the original version is for 'person'
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
728 if ( !isset($arrayValue[0][$_topic_tag]) ) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
729 unset($outputTableArray[$arrayIndex]);
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
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
732 }
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
733 // -----
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
734
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
735 return $outputTableArray;
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
736 }
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
737
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
738 // === for export table ===
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
739
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
740 public function ExportTable($postdata, $isFromFile) {
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
741 if ($isFromFile) {
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
742 $content = $this->lg_text;
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
743 $topic = $this->topic;
84
ecc4b22e9b05 Bug fixed: missing section id variable in export table from LGservice.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 83
diff changeset
744 $section_id = $this->section_id;
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
745 $sectionName = $this->section_name;
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
746 $bookId = $this->book_id;
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
747 $bookName = $this->book_name;
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
748
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
749 $taglistArray = $this->taglist_infile;
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
750
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
751 } else {
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
752 $content = $postdata['content'];
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
753 $topic = $postdata['topic'];
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
754
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
755 $section_id = $postdata['sectionId'];
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
756 $sectionName = $postdata['sectionName'];
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
757 $bookId = $postdata['bookId'];
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
758 $bookName = $postdata['bookName'];
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
759
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
760 //$taglistArray = $this->GetTaglistArray();
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
761 $taglistArray = $this->GetTaglistByTopicId($topic);
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
762 }
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
763 // =====
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
764
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
765 $topic_tag = $this->GetTopicTag($topic);
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
766
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
767 // input data: taglistArray, topic_tag, content; output: outputTableArray
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
768 $outputTableArray = $this->GetTableArray($taglistArray, $topic_tag, $content);
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
769
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
770
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
771
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
772 // data for view
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
773 $data = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
774 $data['outputTableArray'] = $outputTableArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
775 $data['bookId'] = $bookId;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
776 $data['section_id'] = $section_id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
777 $data['bookName'] = $bookName;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
778 $data['sectionName'] = $sectionName;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
779
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
780 return $data;
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 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
783
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
784 // === for manage tag list ===
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
785 public function EditTaglist($_postdata) {
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
786 /**
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
787 */
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
788
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
789 $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
790 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
791 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
792 echo json_encode(mysql_error());
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
793 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
794 $row = mysql_fetch_assoc($result);
51
840cdb52f476 add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 48
diff changeset
795 $largest_id = $row['AUTO_INCREMENT']-1;
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
796
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
797
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
798 $topic_id = $_postdata['topic_id'];
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
799 $result = $this->GetTaglistByTopicId($topic_id);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
800
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
801 $taglistArray = array();
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 foreach ($result as $row) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
804 $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
805 //$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
806 }
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 $topic_tag_name = $this->GetTopicTag($topic_id);
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 $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
811 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
812 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
813 echo json_encode(mysql_error());
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
814 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
815 $row = mysql_fetch_assoc($result);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
816 $topic_tag_id = $row['id'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
817
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
818 $data = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
819 $data['taglistArray'] = $taglistArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
820 $data['topic_id'] = $topic_id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
821 $data['largest_id'] = $largest_id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
822 $data['topic_tag_id'] = $topic_tag_id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
823
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
824
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
825 return $data;
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
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
829 private function GetTag($_postdata) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
830 if (get_magic_quotes_gpc()) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
831 $id = stripslashes($_postdata['id']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
832 $name = stripslashes($_postdata['name']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
833 $tag = stripslashes($_postdata['tag']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
834 $color = stripslashes($_postdata['color']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
835 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
836 $id = $_postdata['id'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
837 $name = $_postdata['name'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
838 $tag = $_postdata['tag'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
839 $color = $_postdata['color'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
840 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
841 return array($id, $name, $tag, $color);
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 NewTagElement($postdata) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
845 if ($postdata['id']){
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
846 list($id, $name, $tag, $color) = $this->GetTag($postdata);
47
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 $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
849 $this->GetSQLValueString($id, "int"),
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
850 $this->GetSQLValueString($name, "text"),
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
851 $this->GetSQLValueString($tag, "text"),
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
852 $this->GetSQLValueString($color, "text"),
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
853 $this->GetSQLValueString($this->systemNAME, "text"));
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
854 $result1 = mysql_query($query1);
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
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
857 // add it to topic_tag_relation table
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
858 $topic_id = $postdata['topic_id'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
859
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
860 // tag_id is $id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
861 $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
862 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
863 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
864 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
865 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
866 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
867
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
868 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
869
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
870 public function SaveTagElement($postdata) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
871 if ($postdata['id']){
67
3ada9334ebfc New: check taglist is deprecated or not
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 66
diff changeset
872 list($id, $name, $tag, $color) = $this->GetTag($postdata);
47
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 $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
875 $this->GetSQLValueString($name, "text"),
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
876 $this->GetSQLValueString($tag, "text"),
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
877 $this->GetSQLValueString($color, "text"),
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
878 $this->GetSQLValueString($id, "int"));
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
879 $result = mysql_query($query);
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
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
883 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
884
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
885 public function DeleteTag($postdata) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
886 if ($postdata['id']) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
887 $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
888 $resultInsert = mysql_query($queryInsert);
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 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
892
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
893 // === for config topic ===
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
894 public function ConfigTagsInTopic($postdata) {
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
895 /**
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
896 *
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
897 */
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
898
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
899 $topic = $postdata['topic'];
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
900 $result = $this->GetTopicById($topic);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
901 $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
902 $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
903 $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
904 $topic_name_pinyin = $row['name_pinyin'];
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
905
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
906 /*
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
907 $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
908 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
909 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
910 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
911 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
912 $taglistArray = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
913 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
914 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
915 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
916 */
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
917
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
918 // ------
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
919 $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
920 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
921 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
922 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
923 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
924
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
925 $tag_intopic = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
926 $tag_others = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
927 $tag_tmp_others = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
928 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
929 if ($row['topic_id'] == $topic) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
930 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
931 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
932 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
933 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
934 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
935
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
936 // --- 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
937 $num_others = count($tag_tmp_others);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
938 for ($i=0; $i < $num_others; $i++) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
939 $cnt = 0;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
940 for ($j=$i+1; $j < $num_others; $j++) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
941 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
942 break;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
943 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
944 $cnt++;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
945 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
946 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
947 if ($cnt == ($num_others-$i-1) ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
948 $row = $tag_tmp_others[$i];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
949 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
950 }
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
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
953 // --- 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
954 $tag_tmp_others = $tag_others;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
955 $tag_others = array();
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 foreach ($tag_tmp_others as $tmp) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
958 $cnt = 0;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
959 foreach ($tag_intopic as $intopic) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
960 if ($tmp['tag'] == $intopic['tag']) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
961 break;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
962 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
963 $cnt ++;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
964 }
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 if ($cnt == count($tag_intopic)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
967 // not appear in $tag_intopic
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
968 array_push($tag_others, $tmp);
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
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
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
975 $data = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
976 //$data['taglistArray'] = $taglistArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
977 $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
978 $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
979
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
980 $data['tag_intopic'] = $tag_intopic;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
981 $data['tag_others'] = $tag_others;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
982
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
983 return $data;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
984 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
985
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
986
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
987 public function UpdateTagsInTopic($_postdata) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
988 $topic_id = $_postdata['topic_id'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
989 $tag_ids = json_decode(str_replace('\\', '', $_postdata['ids']));
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 // 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
992 // --- add new topic_tag_relation ---
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
993 foreach ($tag_ids as $tag_id) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
994 $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
995 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
996 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
997 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
998 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
999 $topic_tag = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1000 $flag = false;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1001 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1002 if ($row['topic_id'] == $topic_id) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1003 $flag = true;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1004 break;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1005 }
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 if (!$flag) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1008 // insert a row into topic_tag_relation table
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1009 $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
1010 $resultUpdate = mysql_query($queryUpdate);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1011 if (!$resultUpdate) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1012 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
1013 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1014 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1015
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1016 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1017
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1018 // --- remove tags from this topic ---
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1019 $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
1020 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1021 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1022 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
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 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1026 $cnt = 0;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1027 foreach ($tag_ids as $tag_id) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1028 if ($row['tag_id'] == $tag_id) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1029 break;
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 $cnt ++;
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 $_id = $row['id'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1035 if ($cnt == count($tag_ids)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1036 // delete row with (topic_id, tag_ids)
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1037 $queryDelete = "DELETE FROM topic_tag_relation WHERE id=".$_id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1038 $resultDelete = mysql_query($queryDelete);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1039 if (!$resultDelete) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1040 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
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 }
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
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1046
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1047 /*
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1048 $query = "SELECT * FROM topic_tag_relation";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1049 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1050 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1051 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
1052 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1053 $topic_tag = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1054 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1055 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
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
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1059 foreach ($topic_tag as $value) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1060 $flag = false;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1061 foreach ($tag_ids as $tag_id) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1062 if ($value['tag_id'] == $tag_id) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1063 //update its topic_id to $topic_id
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1064 $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
1065 $resultUpdate = mysql_query($queryUpdate);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1066 if (!$resultUpdate) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1067 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
1068 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1069 $flag = true;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1070 break;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1071 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1072 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1073 if (!$flag && $value['topic_id'] == $topic_id) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1074 // set its topic_id to 0, indicating unsigned
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1075 $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
1076 $resultUpdate = mysql_query($queryUpdate);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1077 if (!$resultUpdate) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1078 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
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 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1082 */
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
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
1087 private function GetTaglistByTopicId($topic_id) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1088 $taglistArray = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1089 // select taglist ids from topic_tag_relation table
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1090 $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
1091 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1092 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1093 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
1094 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1095 $taglist_ids = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1096
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1097 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1098 array_push($taglist_ids, $row['tag_id']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1099 }
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 // select taglist by tag ids
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1102 foreach ($taglist_ids as $tag_id) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1103 $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
1104 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1105 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1106 echo mysql_error();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1107 return json_encode("Failed during selecting taglist table.");
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
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1110 $row = mysql_fetch_assoc($result);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1111 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
1112
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1113 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1114 return $taglistArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1115 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1116
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1117 public function SetTopic($topic) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1118 $this->topic = $topic;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1119 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1120
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
1121 private function GetTopic() {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1122 return $this->topic;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1123 }
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 private function GetTopiclistArray() {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1126 $topiclistArray = array();
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
1127 $result = $this->GetTopicList();
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1128 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
1129 //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
1130 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
1131 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1132 return $topiclistArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1133 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1134
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 private function GetTopicTag($topic_id) {
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
1137 $result = $this->GetTopicById($topic_id);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1138 $row = mysql_fetch_assoc($result);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1139 $tag = $row['tag'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1140 return $tag;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1141 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1142 private function GetTopicName($topic_id) {
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
1143 $result = $this->GetTopicById($topic_id);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1144 $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
1145 //$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
1146 $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
1147 return $name;
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
1148 }
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
1149 private function GetTopicTagName($topic_id) {
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
1150 $topic_tag = $this->GetTopicTag($topic_id);
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
1151 $query = "SELECT * FROM `taglist` WHERE tag='".$topic_tag."'";
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
1152 $result = mysql_query($query);
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
1153 $row = mysql_fetch_assoc($result);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1154
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
1155 return $row['name'];
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1156 }
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
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
1159
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
1160
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1161 // ===========================
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1162
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1163 // === for manage wordlist ===
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1164 public function EditWordlist() {
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1165 /**
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1166 * EditWordlist shows the wordlist in a new window.
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1167 * User can view each one of the wordlist and edit it, also s/he can create a new wordlist here.
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1168 */
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1169
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1170 $result = $this->GetWordlist();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1171 $wordlistArray = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1172 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1173 $wordlistArray[$row['id']] = $row['name'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1174 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1175
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1176 $data = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1177 $data['wordlistArray'] = $wordlistArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1178 return $data;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1179 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1180
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1181
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1182 public function AddNewList($postdata) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1183 if ($postdata['text']){
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1184 if (get_magic_quotes_gpc()) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1185 $name = stripslashes($postdata['text']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1186 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1187 $name = $postdata['text'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1188 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1189
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1190 $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
1191 $this->GetSQLValueString($name, "text"),
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1192 $this->GetSQLValueString($this->systemNAME, "text"));
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1193 $result1 = mysql_query($query1);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1194 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
1195 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1196 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1197
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1198
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1199 public function SaveWordlist($postdata) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1200
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1201 if ($postdata['text']){
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1202 $date = date('Y_m_d_H_i_s', time());
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1203 if ( file_exists("data/wordlist/".$postdata['filename'].".txt") ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1204 $filename = "data/wordlist/".$postdata['filename']."_".$date.".txt";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1205 $oldFile = file_get_contents("data/wordlist/".$postdata['filename'].".txt");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1206 file_put_contents($filename, $oldFile);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1207 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1208 /*else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1209 $filename = "data/wordlist/".$postdata['filename'].".txt";
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 */
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1212
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1213
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1214 if (get_magic_quotes_gpc()) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1215 $require = stripslashes($postdata['text']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1216 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1217 $require = $postdata['text'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1218 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1219
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1220 $require = preg_replace("/<br>/u", "<br>", $require);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1221 file_put_contents("data/wordlist/".$postdata['filename'].".txt", $require);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1222 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1223 /*
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1224 if ($postdata['text']){
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1225 $date = date('Y_m_d_H_i_s', time());
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1226 if ( file_exists("data/wordlist/".$postdata['filename'].".txt") ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1227 $oldFile = file_get_contents("data/wordlist/".$postdata['filename'].".txt");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1228 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
1229 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1230
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1231 if (get_magic_quotes_gpc()) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1232 $require = stripslashes($postdata['text']);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1233 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1234 $require = $postdata['text'];
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 // $require = preg_replace("/<br>/u", "", $require);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1238 file_put_contents("data/wordlist/".$postdata['filename'].".txt", $require);
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 */
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1241 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1242
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1243
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1244 // =======================================
79
e6e213b26454 Bug fixed: file crashed after saving (preg_replace remove unnecessary symbols within br tag
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 78
diff changeset
1245
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
1246 private function sortFunction($a,$b) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1247 return strlen($b)-strlen($a);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1248 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1249
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1250 private function GetSectionId() {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1251
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1252 if (is_numeric($this->section_id)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1253 return $this->section_id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1254 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1255 return json_encode("Error: No section id");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1256 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1257 }
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 private function GetSectionInfo() {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1260 $section_id = $this->GetSectionId();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1261 if (!is_numeric($section_id)){
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1262 return $section_id;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1263 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1264
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
1265 $result = $this->GetSectionsById($section_id);
47
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
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1268 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1269 $bookId=$row['books_id'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1270 $startPage=$row['start_page'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1271 $endPage=$row['end_page'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1272 $sectionName = $row['name'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1273 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1274
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1275 $data = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1276 $data['bookId'] = $bookId;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1277 $data['startPage'] = $startPage;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1278 $data['endPage'] = $endPage;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1279 $data['sectionName'] = $sectionName;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1280
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 return $data;
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
74
60b5a94163c3 New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 73
diff changeset
1285 private function ParseDataInFile($filename) {
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1286 $text = file_get_contents($filename);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1287 $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
1288 if (!$xml) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1289 // 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
1290 return $text;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1291 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1292
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1293 $this->topic = (string)$xml->topic; // set topic id
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1294
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1295 // get taglist in file
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1296 $taglist_infile = $xml->tagitem;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1297 $taglistArray = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1298 foreach ($taglist_infile as $row) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1299 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
1300 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1301 if ($taglistArray) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1302 $this->taglist_infile = $taglistArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1303 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1304
74
60b5a94163c3 New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 73
diff changeset
1305 // --- 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
1306 /*
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1307 $book_meta = $xml->book;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1308 $book_metaArray = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1309 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
1310 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
1311 (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
1312 (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
1313 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1314 if ($book_metaArray) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1315 $this->book_meta = $book_metaArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1316 }
74
60b5a94163c3 New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 73
diff changeset
1317 */
60b5a94163c3 New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 73
diff changeset
1318 // -----
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1319 // TODO: get section_id, section_name from file
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1320 if ($this->section_id == 0 && isset($xml->section)) {
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1321 if ($xml->section) {
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1322 $this->section_id = (string)$xml->section->id;
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1323 $this->section_name = (string)$xml->section->name;
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1324 }
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1325 }
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1326 // book meta data
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1327 if (!isset($this->book_id) && isset($xml->book)) {
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1328 $this->book_id = (string)$xml->book->id;
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1329 $this->book_name = (string)$xml->book->name;
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1330 }
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1331
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1332
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
1333
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
1334 $contentString = (string)($xml->text_content->asXML());
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1335
76
c49192885290 Bug fixed: ambiguous tag occured at Editing-text mode
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 75
diff changeset
1336 $removed_str = array("<text_content>","</text_content>");
c49192885290 Bug fixed: ambiguous tag occured at Editing-text mode
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 75
diff changeset
1337 $new_contentString = str_replace($removed_str, "", $contentString);
c49192885290 Bug fixed: ambiguous tag occured at Editing-text mode
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 75
diff changeset
1338
c49192885290 Bug fixed: ambiguous tag occured at Editing-text mode
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 75
diff changeset
1339 return $new_contentString;
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1340 }
74
60b5a94163c3 New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 73
diff changeset
1341
60b5a94163c3 New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 73
diff changeset
1342
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1343 private function GetSectionContent() {
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 79
diff changeset
1344 /** This is only been called by SetTextFromLocal().
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1345 */
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 76
diff changeset
1346
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1347 $section_id = $this->GetSectionId();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1348 $section_info = $this->GetSectionInfo();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1349
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1350 $bookId = $section_info['bookId'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1351 $startPage = $section_info['startPage'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1352 $endPage = $section_info['endPage'];
86
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
1353 $this->section_name = $section_info['sectionName'];
0141df465205 New: add chinese characters to pinyin
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 84
diff changeset
1354
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1355
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1356 $contentString="";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1357 $data_path = $this->GetDataPath();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1358 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
1359 $filename = $data_path."parsing_files/".$section_id.".txt";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1360
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1361 // --- parsing meta data
74
60b5a94163c3 New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 73
diff changeset
1362 $stringInput = $this->ParseDataInFile($filename);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1363 // ----
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1364
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1365 // if the text is from file system
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1366 $stringInput = preg_replace("/ /u", "○", $stringInput);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1367 $stringInput = preg_replace("/\n/u", "<br>", $stringInput);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1368 $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
1369
3395385476d1 bug fixed: popup tag window is closed automatically when saving text file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 62
diff changeset
1370 $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
1371
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1372 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1373 $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
1374 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1375 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1376 return json_encode("Failed during selecting content table.");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1377 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1378 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1379 $contentString.="【".$row['line']."】".$row['content']."\n";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1380 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1381
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1382 // the text is from database
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1383 $stringInput = $contentString;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1384 $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1385 $stringInput = preg_replace("/ /u", "○", $stringInput);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1386 $stringInput = preg_replace("/\n/u", "<br>", $stringInput);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1387 $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
1388 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1389
69
edb8a2e8ce84 New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 67
diff changeset
1390 /*
74
60b5a94163c3 New: retrieve book meta data from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 73
diff changeset
1391 // 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
1392 $book_meta = array();
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
1393 $books_result = $this->GetBooksById($bookId);
51
840cdb52f476 add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 48
diff changeset
1394 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
1395 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
1396 // 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
1397 }
69
edb8a2e8ce84 New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 67
diff changeset
1398 $this->book_meta = $book_meta;
edb8a2e8ce84 New: save book meta_data in file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 67
diff changeset
1399 */
51
840cdb52f476 add book_meta into file
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 48
diff changeset
1400
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1401 return $stringInput;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1402 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1403
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1404 private function GetDataPath() {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1405 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
1406 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1407
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1408 private function GetTaglistArray() {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1409 $taglistArray = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1410 $result = $this->GetTaglist();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1411 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1412 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
1413 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1414
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1415 return $taglistArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1416 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1417
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1418 private function GetWordlistArray() {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1419 $wordlistArray="";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1420 $result = $this->GetWordlist();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1421 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1422 $listString = file_get_contents("data/wordlist/".$row['id'].".txt");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1423 $listString = preg_replace("/<div>/u", "\n", $listString);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1424 $listString = preg_replace("/<\/div>/u", "", $listString);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1425 $listString = preg_replace("/<span(.*?)>/u", "", $listString);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1426 $listString = preg_replace("/<\/span>/u", "", $listString);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1427 //$listString = preg_replace("/\n/u", "|", $listString);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1428
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1429 $wordlistArray2 = explode( "\n", $listString );
71
26d8c4c43d86 minor checking for variable/index in php
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 70
diff changeset
1430 //usort($wordlistArray2,'sortFunction');
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1431 foreach ( $wordlistArray2 as $index=>$value ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1432 $wordlistArray2[$index] = implode("○?", preg_split("/(?<!^)(?!$)/u", $value));
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1433 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1434 foreach ( $wordlistArray2 as $index=>$value ) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1435 if ($value=="") unset($wordlistArray2[$index]);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1436
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1437 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1438 $listString = implode("|", $wordlistArray2);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1439
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1440 if ( $listString[0]=="|" ) $listString = substr($listString, 1);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1441 $wordlistArray[] = array( $row['id'], $row['name'], $listString );
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1442 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1443
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1444
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1445 return $wordlistArray;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1446
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1447 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1448
78
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
1449 private function GetBooksInfo($bookId) {
960ba96efce1 Update: click to popup remove-tag-window; select to popup tag-window
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
1450 $result = $this->GetSectionsById($bookId);
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1451 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1452 $bookName = $row['name'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1453 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1454
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1455 $data = array();
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1456 $data['bookName'] = $bookName;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1457
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1458 return $data;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1459 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1460
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1461
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1462 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1463
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1464
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1465
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1466 ?>