function wikiplugin_webservice( $data, $params ) { require_once 'lib/ointegratelib.php'; if ( isset( $params['bodyname'] ) && ! empty($params['bodyname']) ) { $params[ $params['bodyname'] ] = $data; unset($params['bodyname']); $data = ''; } if ( isset( $params['params'] )) { parse_str($params['params'], $request_params); $params = array_merge($params, $request_params); } if ( ! empty( $data ) ) { $templateFile = $GLOBALS['tikipath'] . 'temp/cache/' . md5($data); if ( ! file_exists($templateFile) ) file_put_contents($templateFile, $data); } else { $templateFile = ''; } if ( isset( $params['url'] ) ) { // When URL is specified, always use the body as template $request = new OIntegrate; $response = $request->performRequest($params['url']); if ( ! empty( $templateFile ) ) return $response->render('smarty', 'tikiwiki', 'tikiwiki', $templateFile); } elseif ( isset($params['service']) && (isset($params['template']) || !empty( $templateFile ) )) { require_once 'lib/webservicelib.php'; if ( $service = Tiki_Webservice::getService($params['service']) ) { if ( ! empty( $templateFile ) ) { // Render using function body $response = $service->performRequest($params); return $response->render('smarty', 'tikiwiki', 'tikiwiki', $templateFile); } elseif ( $template = $service->getTemplate($params['template']) ) { $response = $service->performRequest($params); return $template->render($response, 'tikiwiki'); } else { return '^' . tra('Unknown Template') . '^'; } } else { return '^' . tra('Unknown Service') . '^'; } } else { return '^' . tra('Missing parameters') . '^'; } }
private function getTranslationFromGoogle($text) { require_once 'lib/ointegratelib.php'; $ointegrate = new OIntegrate(); $params = array('key' => $this->key, 'target' => $this->targetLang, 'q' => $text, 'format' => $this->markup === self::HTML_MARKUP ? 'html' : 'text'); if ($this->sourceLang != Multilingual_MachineTranslation::DETECT_LANGUAGE) { $params['source'] = $this->sourceLang; } $url = self::SERVICE_URL . '?' . http_build_query($params, '', '&'); $oi_result = $ointegrate->performRequest($url); $result = $oi_result->data['data']['translations']; return implode('', array_map(function ($entry) { return $entry['translatedText']; }, $result)); }
/** * @param $params * @param bool $fullReponse * @return bool|OIntegrate_Response */ function performRequest($params, $fullReponse = false) { global $soaplib, $prefs; $built = $this->url; $builtBody = $this->body; $map = $this->getParameterMap($params); if ($built) { switch ($this->wstype) { case 'SOAP': if (!empty($this->operation)) { $options = array('encoding' => 'UTF-8'); if ($prefs['use_proxy'] == 'y' && !strpos($built, 'localhost')) { $options['proxy_host'] = $prefs['proxy_host']; $options['proxy_port'] = $prefs['proxy_port']; } $response = new OIntegrate_Response(); $soaplib->allowCookies = $this->allowCookies; try { $response->data = $soaplib->performRequest($built, $this->operation, $map, $options, $fullReponse); } catch (Exception $e) { TikiLib::lib('errorreport')->report(tr('Webservice error on %0 request "%1"', $this->wstype, $this->url) . '<br>' . $e->getMessage()); } return $response; } return false; case 'REST': default: foreach ($map as $name => $value) { $built = str_replace("%{$name}%", urlencode($value), $built); $builtBody = str_replace("%{$name}%", urlencode($value), $builtBody); } $ointegrate = new OIntegrate(); $ointegrate->addAcceptTemplate('smarty', 'tikiwiki'); $ointegrate->addAcceptTemplate('smarty', 'html'); $ointegrate->addAcceptTemplate('javascript', 'html'); if ($this->schemaVersion) { $ointegrate->addSchemaVersion($this->schemaVersion); } try { $response = $ointegrate->performRequest($built, $builtBody); } catch (Exception $e) { TikiLib::lib('errorreport')->report(tr('Webservice error on %0 request "%1"', $this->wstype, $this->url) . '<br>' . $e->getMessage()); } return $response; } } }
function render($engine, $engineOutput, $outputContext, $templateFile) { $engine = OIntegrate::getEngine($engine, $engineOutput); if (!($output = OIntegrate::getConverter($engineOutput, $outputContext))) { $this->errors = array(1001, 'Output converter not found.'); return; } if (!$engine) { $this->errors = array(1000, 'Engine not found'); return; } $raw = $engine->process($this->data, $templateFile); return $output->convert($raw); }
function getTranslationFromGoogle($encodedText, $encodedLangpair) { $url = $this->googleAjaxUrl . "&q=" . $encodedText . "&langpair=" . $encodedLangpair; $ointegrate = new OIntegrate(); $oi_result = $ointegrate->performRequest($url); $result = $oi_result->data['responseData']['translatedText']; return $result; }