Index: branches/RC/core/install/install_schema.sql =================================================================== diff -u -N -r10906 -r10908 --- branches/RC/core/install/install_schema.sql (.../install_schema.sql) (revision 10906) +++ branches/RC/core/install/install_schema.sql (.../install_schema.sql) (revision 10908) @@ -612,4 +612,13 @@ KEY LastRunStatus (LastRunStatus), KEY RunTime (RunTime), KEY NextRunOn (NextRunOn) -); \ No newline at end of file +); + +CREATE TABLE SpellingDictionary ( + SpellingDictionaryId int(11) NOT NULL auto_increment, + MisspelledWord varchar(255) NOT NULL default '', + SuggestedCorrection varchar(255) NOT NULL default '', + PRIMARY KEY (SpellingDictionaryId), + KEY MisspelledWord (MisspelledWord), + KEY SuggestedCorrection (SuggestedCorrection) +); Index: branches/RC/core/units/categories/categories_tag_processor.php =================================================================== diff -u -N -r10538 -r10908 --- branches/RC/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 10538) +++ branches/RC/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 10908) @@ -769,6 +769,86 @@ return $this->Application->HREF($t, '', $params); } + + + /** + * Returns spelling suggestions against search keyword + * + * @param Array $params + * @return string + */ + function SpellingSuggestions($params) + { + $keywords = unhtmlentities( trim($this->Application->GetVar('keywords')) ); + if (!$keywords) { + return ; + } + + // 1. try to get already cached suggestion + $suggestion = $this->Application->getCache('search.suggestion', $keywords); + if ($suggestion !== false) { + return $suggestion; + } + + $table_name = $this->Application->getUnitOption('spelling-dictionary', 'TableName'); + + // 2. search suggestion in database + $sql = 'SELECT SuggestedCorrection + FROM ' . $table_name . ' + WHERE MisspelledWord = ' . $this->Conn->qstr($keywords); + $suggestion = $this->Conn->GetOne($sql); + if ($suggestion !== false) { + $this->Application->setCache('search.suggestion', $keywords, $suggestion); + return $suggestion; + } + + // 3. suggestion not found in database, ask webservice + $app_id = $this->Application->ConfigValue('YahooApplicationId'); + $url = 'http://search.yahooapis.com/WebSearchService/V1/spellingSuggestion?appid=' . $app_id . '&query='; + + $curl_helper =& $this->Application->recallObject('CurlHelper'); + /* @var $curl_helper kCurlHelper */ + + $xml_data = $curl_helper->Send($url . urlencode($keywords)); + + $xml_helper =& $this->Application->recallObject('kXMLHelper'); + /* @var $xml_helper kXMLHelper */ + + $root_node =& $xml_helper->Parse($xml_data); + + $result = $root_node->FindChild('RESULT'); + /* @var $result kXMLNode */ + + if (is_object($result)) { + // webservice responded -> save in local database + $fields_hash = Array ( + 'MisspelledWord' => $keywords, + 'SuggestedCorrection' => $result->Data, + ); + + $this->Conn->doInsert($fields_hash, $table_name); + $this->Application->setCache('search.suggestion', $keywords, $result->Data); + + return $result->Data; + } + + return ''; + } + + /** + * Shows link for searching by suggested word + * + * @param Array $params + * @return string + */ + function SuggestionLink($params) + { + $params['keywords'] = $this->SpellingSuggestions($params); + + return $this->Application->ProcessParsedTag('m', 'Link', $params); + } + + } ?> \ No newline at end of file Index: branches/RC/core/install/upgrades.sql =================================================================== diff -u -N -r10906 -r10908 --- branches/RC/core/install/upgrades.sql (.../upgrades.sql) (revision 10906) +++ branches/RC/core/install/upgrades.sql (.../upgrades.sql) (revision 10908) @@ -349,3 +349,15 @@ ALTER TABLE `Language` ADD `FilenameReplacements` TEXT NULL ; +CREATE TABLE SpellingDictionary ( + SpellingDictionaryId int(11) NOT NULL auto_increment, + MisspelledWord varchar(255) NOT NULL default '', + SuggestedCorrection varchar(255) NOT NULL default '', + PRIMARY KEY (SpellingDictionaryId), + KEY MisspelledWord (MisspelledWord), + KEY SuggestedCorrection (SuggestedCorrection) +); + + +INSERT INTO ConfigurationValues VALUES(NULL, 'YahooApplicationId', '56QxES3V34FXHPPcrPI_6.0mjc6QIG4AnHP0OC2LZEePW0nq_uNG.kVmSKG4llurekJ.OIE-', 'In-Portal', 'in-portal:configure_categories'); +INSERT INTO ConfigurationAdmin VALUES('YahooApplicationId', 'la_Text_General', 'la_config_YahooApplicationId', 'text', NULL, NULL, 10.15, 0, 0); \ No newline at end of file Index: branches/RC/admin/install/inportal_remove.sql =================================================================== diff -u -N -r10900 -r10908 --- branches/RC/admin/install/inportal_remove.sql (.../inportal_remove.sql) (revision 10900) +++ branches/RC/admin/install/inportal_remove.sql (.../inportal_remove.sql) (revision 10908) @@ -236,4 +236,6 @@ # -------------------------------------------------------- DROP TABLE SlowSqlCapture # -------------------------------------------------------- -DROP TABLE Agents \ No newline at end of file +DROP TABLE Agents +# -------------------------------------------------------- +DROP TABLE SpellingDictionary \ No newline at end of file Index: branches/RC/core/install/english.lang =================================================================== diff -u -N -r10906 -r10908 --- branches/RC/core/install/english.lang (.../english.lang) (revision 10906) +++ branches/RC/core/install/english.lang (.../english.lang) (revision 10908) @@ -3,18 +3,22 @@ TGFzdCBSdW4gT24= TGFzdCBSdW4gU3RhdHVz + TWlzc3BlbGxlZCBXb3Jk TmV4dCBSdW4gT24= UnVuIEludGVydmFs UnVuIE1vZGU= + U3VnZ2VzdGVkIENvcnJlY3Rpb24= RmlsZW5hbWUgU3BlY2lhbCBDaGFyIFJlcGxhY2VtZW50 RXZlbnQ= RmlsZW5hbWUgUmVwbGFjZW1lbnRz TGFzdCBSdW4gT24= TGFzdCBSdW4gU3RhdHVz + TWlzc3BlbGxlZCBXb3Jk TmV4dCBSdW4gT24= UnVuIEludGVydmFs UnVuIE1vZGU= UnVuIFRpbWU= + U3VnZ2VzdGVkIENvcnJlY3Rpb24= VHlwZQ== QWN0aXZl QWZ0ZXI= @@ -26,9 +30,12 @@ U3lzdGVt VXNlcg== QWRkaW5nIEFnZW50 + QWRkaW5nIFNwZWxsaW5nIERpY3Rpb25hcnk= QWdlbnRz RWRpdGluZyBBZ2VudA== + RWRpdGluZyBTcGVsbGluZyBEaWN0aW9uYXJ5 TmV3IEFnZW50 + U3BlbGxpbmcgRGljdGlvbmFyeQ== \ No newline at end of file Index: branches/RC/core/install/install_data.sql =================================================================== diff -u -N -r10906 -r10908 --- branches/RC/core/install/install_data.sql (.../install_data.sql) (revision 10906) +++ branches/RC/core/install/install_data.sql (.../install_data.sql) (revision 10908) @@ -87,6 +87,7 @@ INSERT INTO ConfigurationAdmin VALUES ('KeepSessionOnBrowserClose', 'la_Text_Website', 'la_config_KeepSessionOnBrowserClose', 'checkbox', '', '', 10.27, 0, 0); INSERT INTO ConfigurationAdmin VALUES ('ForceImageMagickResize', 'la_Text_Website', 'la_config_ForceImageMagickResize', 'checkbox', '', '', 10.28, 0, 0); INSERT INTO ConfigurationAdmin VALUES ('RememberLastAdminTemplate', 'la_Text_General', 'la_config_RememberLastAdminTemplate', 'checkbox', '', '', 10.13, 0, 0); +INSERT INTO ConfigurationAdmin VALUES('YahooApplicationId', 'la_Text_General', 'la_config_YahooApplicationId', 'text', NULL, NULL, 10.28, 0, 0); INSERT INTO ConfigurationValues VALUES (DEFAULT, 'Columns_Category', '2', 'In-Portal', 'Categories'); INSERT INTO ConfigurationValues VALUES (DEFAULT, 'DomainSelect','1','In-Portal','in-portal:configure_general'); @@ -248,6 +249,7 @@ INSERT INTO ConfigurationValues VALUES (DEFAULT, 'KeepSessionOnBrowserClose', '0', 'In-Portal', 'in-portal:configure_general'); INSERT INTO ConfigurationValues VALUES (DEFAULT, 'ForceImageMagickResize', '0', 'In-Portal', 'in-portal:configure_general'); INSERT INTO ConfigurationValues VALUES (DEFAULT, 'RememberLastAdminTemplate', '', 'In-Portal:Users', 'in-portal:configure_users'); +INSERT INTO ConfigurationValues VALUES(NULL, 'YahooApplicationId', '', 'In-Portal', 'in-portal:configure_categories'); INSERT INTO Events VALUES (DEFAULT, 'USER.ADD', NULL, 1, 0, 'In-Portal:Users', 'la_event_user.add', 0); INSERT INTO Events VALUES (DEFAULT, 'USER.ADD', NULL, 2, 0, 'In-Portal:Users', 'la_event_user.add', 1);