| 1 | <?php |
|---|
| 2 | require_once(WCF_DIR.'lib/acp/page/UserSuggestPage.class.php'); |
|---|
| 3 | |
|---|
| 4 | // Tagging util |
|---|
| 5 | require_once(WCF_DIR.'lib/util/TaggingReloadedUtil.class.php'); |
|---|
| 6 | |
|---|
| 7 | /** |
|---|
| 8 | * receives input text, filters the words and returns tags as xml |
|---|
| 9 | * |
|---|
| 10 | * @author Torben Brodt |
|---|
| 11 | * @package de.easy-coding.wcf.taggingreloaded |
|---|
| 12 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
|---|
| 13 | */ |
|---|
| 14 | class TaggingReloadedQueryPage extends UserSuggestPage { |
|---|
| 15 | public $query= ''; |
|---|
| 16 | |
|---|
| 17 | /** |
|---|
| 18 | * @see Page::readParameters() |
|---|
| 19 | */ |
|---|
| 20 | public function readParameters() { |
|---|
| 21 | parent::readParameters(); |
|---|
| 22 | |
|---|
| 23 | if (isset($_POST['query'])) { |
|---|
| 24 | $this->query = StringUtil::trim($_POST['query']); |
|---|
| 25 | if (CHARSET != 'UTF-8') $this->query = StringUtil::convertEncoding('UTF-8', CHARSET, $this->query); |
|---|
| 26 | } |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | /** |
|---|
| 30 | * @see Page::readData() |
|---|
| 31 | */ |
|---|
| 32 | public function readData() { |
|---|
| 33 | // unify languages "en-us" to "en" and "de-informal" to "de" |
|---|
| 34 | $lang = explode('-', WCF::getLanguage()->getLanguageCode()); |
|---|
| 35 | $lang = $lang[0]; |
|---|
| 36 | |
|---|
| 37 | $query = TaggingUtil::text2tags($this->query); |
|---|
| 38 | $stopwords = array(); |
|---|
| 39 | |
|---|
| 40 | $sql = "SELECT stopword |
|---|
| 41 | FROM wcf".WCF_N."_taggingreloaded_stopwords |
|---|
| 42 | WHERE languagecode = '{$lang}'; "; |
|---|
| 43 | $result = WCF::getDB()->sendQuery($sql); |
|---|
| 44 | while ($row = WCF::getDB()->fetchArray($result)) { |
|---|
| 45 | $stopwords[] = $row['stopword']; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | $this->results = array_diff($query, $stopwords); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * @see Page::show() |
|---|
| 53 | */ |
|---|
| 54 | public function show() { |
|---|
| 55 | //parent::show(); |
|---|
| 56 | header('Content-type: text/xml'); |
|---|
| 57 | echo "<?xml version=\"1.0\" encoding=\"".CHARSET."\"?>\n<suggestions>\n"; |
|---|
| 58 | |
|---|
| 59 | foreach($this->results as $tag => $weight) { |
|---|
| 60 | printf("<tag weight=\"%d\"><![CDATA[%s]]></tag>\n", $weight, StringUtil::escapeCDATA($tag)); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | echo '</suggestions>'; |
|---|
| 64 | exit; |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | ?> |
|---|