Beispiel #1
0
 public static function tearDownAfterClass()
 {
     // Enable back FirePHP
     KBIDebug::setEnabled(true);
     // TODO: solve The process cannot access the file 'results_DD_20130701-10631.xml' because it is being used by another process.'
     // self::$object->unregister();
 }
Beispiel #2
0
 public function queryGet($query)
 {
     $url = $this->getUrl();
     $data = array('topicmap' => $this->getTopicMap(), 'tolog' => $query);
     if ($this->getSyntax() != '') {
         $data['syntax'] = $this->getSyntax();
     }
     KBIDebug::info(array($url, $data));
     return $this->requestCurl($url, $data);
 }
Beispiel #3
0
 function replace($match)
 {
     if (!isset($match[1]) || empty($match[1])) {
         return;
     }
     try {
         //WYSIWYG editor zalamuje XHTML neparove znacky na \ /> aby zustal validni JSON je potreba to vratit spet na \/>
         $json = str_replace('\\ />', '\\/>', $match[1]);
         $config = json_decode($json, true);
         if ($config === NULL) {
             KBIDebug::log($match[1], 'Element not parsed as JSON');
             return $match[1];
         }
         $transfomator = new KbiModelTransformator($config);
         //var_dump($match);
         //var_dump($config);
         //var_dump($transfomator);
         return $transfomator->transform();
     } catch (Exception $ex) {
         KBIDebug::log(array($ex, $config), 'Query not succesfull');
     }
 }
 public function test()
 {
     try {
         $server_id = $this->getMinerId();
         if ($server_id === null) {
             throw new \Exception('LISpMiner ID was not provided.');
         }
         $client = $this->getRestClient();
         $credentials = $this->getUser();
         $url = trim($this->getUrl(), '/');
         $url = "{$url}/miners/{$server_id}";
         $response = $client->get($url, null, $credentials);
         KBIDebug::log($response, "Test executed");
         $this->parseResponse($response, '');
         return true;
     } catch (\Exception $ex) {
         return false;
     }
 }
Beispiel #5
0
 function remove()
 {
     global $option;
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     $this->setRedirect("index.php?option={$option}");
     // Initialize variables
     $db =& JFactory::getDBO();
     $ids = JRequest::getVar('cid', array(0), 'post', 'array');
     $table =& JTable::getInstance('source', 'Table');
     $n = count($ids);
     for ($i = 0; $i < $n; $i++) {
         $sources =& $this->getModel('sources');
         $source = $sources->getSource((int) $ids[$i]);
         // delete miner if it is LISpMiner
         if ($source && $source->type == 'LISPMINER') {
             try {
                 $config = get_object_vars($source);
                 JLoader::import('KBIntegrator', JPATH_PLUGINS . DS . 'kbi');
                 $miner = KBIntegrator::create($config);
                 $miner->unregister();
             } catch (Exception $ex) {
                 // Just log it
                 KBIDebug::log($ex->getMessage());
             }
         }
         if (!$table->delete((int) $ids[$i])) {
             return JError::raiseWarning(500, $table->getError());
         }
     }
     $this->setMessage(JText::sprintf('Items removed', $n));
 }
Beispiel #6
0
 function requestCurl($url, $_data)
 {
     $data = array();
     while (list($n, $v) = each($_data)) {
         $data[] = "{$n}=" . urlencode($v);
     }
     $data = implode('&', $data);
     KBIDebug::info("{$url}?{$data}");
     $ch = curl_init("{$url}?{$data}");
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $response = curl_exec($ch);
     //optionally you can check the response and see what the HTTP Code returned was
     $response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     curl_close($ch);
     return $response;
 }
Beispiel #7
0
 public function getDataDescription()
 {
     $postdata = array('action' => 'getDescription', 'id' => '', 'content' => '');
     $url = $this->getUrl();
     KBIDebug::info(array($url, $postdata));
     $dd = $this->requestCurlPost($url, $postdata);
     $replace1 = '<?xml version="1.0" encoding="UTF-8"?>';
     $replace2 = '</result>';
     $replace3 = '/\\<result milisecs=".*">/U';
     //$replace3 = '/\<!-- kbiLink({.*\}) \/kbiLink -->/U';
     $dd = str_replace($replace1, '', $dd);
     $dd = str_replace($replace2, '', $dd);
     $dd = preg_replace($replace3, '', $dd);
     return trim($dd);
 }
Beispiel #8
0
 /**
  * @param $id
  * @throws Exception
  */
 public function remove($id)
 {
     $table =& JTable::getInstance('source', 'Table');
     $id = (int) $id;
     $source = $this->getSource($id);
     // delete miner if it is LISpMiner
     if ($source && $source->type == 'LISPMINER') {
         try {
             $config = get_object_vars($source);
             JLoader::import('KBIntegrator', JPATH_LIBRARIES . DS . 'kbi');
             $miner = KBIntegrator::create($config);
             $miner->unregister();
         } catch (Exception $ex) {
             // Just log it
             KBIDebug::log($ex->getMessage());
         }
     }
     if (!$table->delete($id)) {
         throw new Exception($table->getError());
     }
 }
Beispiel #9
0
 public function cancelQuery($taskName)
 {
     $source = $this->getSource();
     if ($source != NULL && $source instanceof LispMiner) {
         KBIDebug::log(array('source' => $source, 'task' => $taskName), 'Canceling task');
         return $source->cancelTask($taskName);
     } else {
         return JText::_('Given source does not support query cancelation (only LISpMiner sources does).');
     }
 }
Beispiel #10
0
 function hits()
 {
     $document =& JFactory::getDocument();
     $viewName = JRequest::getVar('view', 'hits');
     $viewType = $document->getType();
     $view =& $this->getView($viewName, $viewType);
     $data = JRequest::getVar('data', '', 'post', 'string', JREQUEST_ALLOWRAW);
     if ($viewType == 'raw' && $data != NULL) {
         $config = array('source' => JRequest::getVar('id_source', NULL, 'default', 'none', JREQUEST_ALLOWRAW), 'query' => NULL, 'xslt' => NULL, 'parameters' => NULL);
         try {
             $com_kbi = JComponentHelper::getComponent('com_kbi', true);
             if (!$com_kbi->enabled) {
                 throw new Exception('KBI component not intalled or enabled');
             }
             JLoader::import('transformator', JPATH_COMPONENT . DS . '..' . DS . $com_kbi->option . DS . 'models');
             $model = new KbiModelTransformator($config);
             $sr = self::createSerializeRules($model->getSource());
             $model->setQuery($sr->serializeRules($data));
             $dd = null;
             $fl = null;
             $er = $model->transform();
             $sr = new GetDataARBuilderQuery($dd, $fl, $er, 'en');
             $data = $sr->getData();
             $view->assignRef('value', $data);
             KBIDebug::log($er);
         } catch (Exception $e) {
             $view->assign('value', "<p class=\"kbierror\">Chyba dotazu: {$e->getMessage()}</p>");
         }
     }
     $view->display();
 }
Beispiel #11
0
 /**
  *
  * Sends PMML document to be indexed to service
  *
  * @see http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html
  */
 public function addDocument($id, $document, $path = true)
 {
     $ch = curl_init();
     if (is_object($document)) {
         $data = array('action' => 'addDocument', 'id' => $id, 'docName' => $document->title, 'creationTime' => $document->modified, 'content' => $document->text, 'reportUri' => $document->uri);
     } else {
         $data = array('action' => 'addDocument', 'id' => $id, 'docName' => '', 'creationTime' => '', 'content' => $path ? file_get_contents($document) : $document);
     }
     curl_setopt($ch, CURLOPT_URL, $this->getUrl());
     curl_setopt($ch, CURLOPT_POSTFIELDS, $this->encodeData($data));
     curl_setopt($ch, CURLOPT_VERBOSE, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POST, true);
     $response = curl_exec($ch);
     $info = curl_getinfo($ch);
     curl_close($ch);
     KBIDebug::log($data);
     KBIDebug::log($info);
     KBIDebug::log($response);
     var_dump($data);
     var_dump($info);
     var_dump($response);
     if ($info['http_code'] != '200') {
         throw new Exception('Error in communication');
     }
 }
Beispiel #12
0
 public function getDatabasePassword($username, $password, $db_id)
 {
     $url = trim($this->getUrl(), '/');
     $url = "{$url}/Users/Get";
     $data = array('name' => $username, 'password' => $password, 'db_id' => $db_id);
     $response = $this->requestGet($url, $data);
     KBIDebug::log(array('data' => $data, 'response' => $response, 'url' => $url), "Password retring");
     return $this->parseDatabasePassword($response);
 }
Beispiel #13
0
 public function setDatabasePassword($username, $password, $db_id, $old_password, $new_password)
 {
     $client = $this->getRestClient();
     $url = trim($this->getUrl(), '/');
     $url = "{$url}/users/{$username}/databases/{$db_id}";
     $data = array('db_id' => $db_id, 'db_password' => $new_password);
     $response = $client->put($url, $data, array('username' => $username, 'password' => $password));
     KBIDebug::log(array('url' => "PUT {$url}", 'data' => $data, 'response' => $response), "Password changed");
     return $this->parseResponse($response, "User's datbases password changed successfully.");
 }
Beispiel #14
0
 protected function tearDown()
 {
     KBIDebug::setEnabled(true);
     unset($this->object);
 }
Beispiel #15
0
 /**
  * Generates final query from skeleton using parameters and/or XSLT transformation.
  *
  * @return string
  */
 public function proccessQuery(&$options)
 {
     $parameters = $this->getParameters();
     $xslt = $this->getXslt();
     /* output parameter */
     $options = array_merge($this->getOptions('GET'), $this->getOptions('POST'));
     if (!empty($parameters)) {
         if (is_array($parameters)) {
             $delimiter = $this->getDelimiter();
             $replace_pairs = array();
             foreach ($parameters as $name => $value) {
                 $replace_pairs[$delimiter . $name . $delimiter] = $value;
             }
             KBIDebug::log($replace_pairs, 'Applying parameters.');
             $this->query = strtr($this->query, $replace_pairs);
         } elseif (empty($this->query) && is_string($parameters)) {
             // in case query is empty and parameters is string then we assume parameters to be query itself
             KBIDebug::info('Parameters considered as query.');
             $this->setQuery($parameters);
         }
     }
     if (!empty($xslt)) {
         $xml = new DOMDocument();
         if ($xml->loadXML($this->query)) {
             // Create XSLT document
             $xsl_document = new DOMDocument();
             $xsl_document->loadXML($xslt, LIBXML_NOCDATA);
             // Process XSLT
             $xslt = new XSLTProcessor();
             $xslt->importStylesheet($xsl_document);
             KBIDebug::info('Applying pre-query transformation.');
             $this->query = $xslt->transformToXML($xml);
         } else {
             KBIDebug::info('Query is not valid XML therefore XSLT could not be executed.');
         }
     }
     return $this->getQuery();
 }
 public function requestGet($url, $_data)
 {
     $data = array();
     while (list($n, $v) = each($_data)) {
         $data[] = "{$n}=" . urlencode($v);
     }
     $data = implode('&', $data);
     $p = file_get_contents("{$url}?{$data}");
     KBIDebug::info("{$url}?{$data}", 'GET');
     return $p;
 }
Beispiel #17
0
 function uploadlocal()
 {
     global $option;
     $application = JFactory::getApplication();
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     if ($model =& $this->getModel('sources')) {
         $id = JRequest::getVar('id', array(0), 'method', 'array');
         $cid = JRequest::getVar('cid', array(0), 'method', 'array');
         $success = 0;
         require_once JPATH_COMPONENT . DS . 'models' . DS . 'documents.php';
         $documents_model = new DocumentsModel();
         $sourceConfig = $model->getSource($id[0]);
         $source = KBIntegrator::create(get_object_vars($sourceConfig));
         foreach ($cid as $document_id) {
             try {
                 $document = $documents_model->getArticle($document_id, 'all', true);
                 if ($document) {
                     KBIDebug::log($document);
                     $source->addDocument($document->id, $document, FALSE);
                     $success++;
                     $application->enqueueMessage(JText::_('Document uploaded') . "({$document->title})");
                 }
             } catch (Exception $ex) {
                 //TODO: add document title to error message
                 $application->enqueueMessage(JText::_('ERROR ADDING FILE') . " - " . $ex->getMessage(), 'error');
             }
         }
         $application->enqueueMessage(JText::_('Documents uploaded') . "({$success})");
     } else {
         $application->enqueueMessage(JText::_('SOURCE NOT FOUND'), 'error');
     }
     $this->setRedirect("index.php?option={$option}&controller=documents&id[]={$id[0]}");
 }
Beispiel #18
0
 /**
  * Generates JSON from FeaturesList and DataDescription that initializes ARDesigner.
  *
  */
 function features()
 {
     $document =& JFactory::getDocument();
     $document->setMimeEncoding('application/json');
     $viewName = JRequest::getVar('view', 'features');
     $viewType = 'raw';
     $view =& $this->getView($viewName, $viewType);
     $query_id = JRequest::getInt('id_query', NULL);
     $view->assign('value', '');
     if ($query_id != NULL) {
         if (!class_exists('KbiModelQueries')) {
             $kbi = JComponentHelper::getComponent('com_kbi', true);
             if ($kbi->enabled) {
                 JLoader::import('queries', self::$com_kbi_admin . DS . 'models');
                 JLoader::import('sources', self::$com_kbi_admin . DS . 'models');
             } else {
                 throw new Exception(JText::_('Component com_kbi not found / enabled!'));
             }
         }
         $model_queries = new KbiModelQueries();
         $query = $model_queries->getQuery($query_id);
         $model_sources = new KbiModelSources();
         $source = $model_sources->getSource(JRequest::getInt('id_source', NULL));
         KBIDebug::log($source);
         $featurelist = !empty($query->featurelist) ? $query->featurelist : $this->featurelist;
         if (!empty($source->dictionaryquery)) {
             $datadescription = $source->dictionaryquery;
         } else {
             $kbi_source = KBIntegrator::create(get_object_vars($source));
             if ($kbi_source instanceof ISynchronable) {
                 $datadescription = $kbi_source->getDataDescription();
             } else {
                 $datadescription = $this->datadescription;
             }
         }
     } else {
         $featurelist = $this->featurelist;
         $datadescription = $this->datadescription;
     }
     if (class_exists('KBIDebug')) {
         KBIDebug::log(array('featurelist' => $featurelist, 'datadescription' => $datadescription), 'Loading ARD with FL and DL');
     }
     $sr = new GetDataARBuilderQuery($datadescription, $featurelist, null, 'en');
     $result = $sr->getData();
     $view->assignRef('value', $result);
     $view->display();
 }