示例#1
0
 function renderOutput($context = array())
 {
     if (!$this->getOption(0) || !$this->getOption(1)) {
         return false;
     }
     require_once 'lib/webservicelib.php';
     if (!($webservice = Tiki_Webservice::getService($this->getOption(0))) || !($template = $webservice->getTemplate($this->getOption(1)))) {
         return false;
     }
     $ws_params = array();
     if ($this->getOption(2)) {
         parse_str($this->getOption(2), $ws_params);
         foreach ($ws_params as $ws_param_name => &$ws_param_value) {
             if (preg_match('/(.*)%(.*)%(.*)/', $ws_param_value, $matches)) {
                 $ws_param_field_name = $matches[2];
             }
             $field = $this->getTrackerDefinition()->getFieldFromName($ws_param_field_name);
             if ($field) {
                 $value = TikiLib::lib('trk')->get_field_value($field, $this->getItemData());
                 $ws_param_value = preg_replace('/%' . $ws_param_field_name . '%/', $value, $ws_param_value);
             }
         }
     }
     $response = $webservice->performRequest($ws_params);
     $output = $template->render($response, 'html');
     return $output;
 }
示例#2
0
 function _install()
 {
     global $tikilib;
     $data = $this->getData();
     $this->replaceReferences($data);
     require_once 'lib/webservicelib.php';
     $ws = Tiki_Webservice::getService($data['webservice']);
     $template = $ws->addTemplate($data['name']);
     $template->engine = $data['engine'];
     $template->output = $data['output'];
     $template->content = $data['content'];
     $template->save();
     return $template->name;
 }
示例#3
0
 function _install()
 {
     global $tikilib;
     $data = $this->getData();
     $this->replaceReferences($data);
     require_once 'lib/webservicelib.php';
     $ws = Tiki_Webservice::create($data['name']);
     $ws->url = $data['url'];
     $ws->body = $data['body'];
     $ws->schemaVersion = $data['schema_version'];
     $ws->schemaDocumentation = $data['schema_documentation'];
     $ws->save();
     return $ws->getName();
 }
示例#4
0
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') . '^';
    }
}
示例#5
0
 function renderOutput($context = array())
 {
     if (!$this->getOption('service') || !$this->getOption('template')) {
         return false;
     }
     require_once 'lib/webservicelib.php';
     if (!($webservice = Tiki_Webservice::getService($this->getOption('service'))) || !($template = $webservice->getTemplate($this->getOption('template')))) {
         return false;
     }
     $oldValue = $this->getValue();
     if (is_string($oldValue)) {
         $oldData = json_decode($oldValue, true);
     } else {
         $oldData = [];
     }
     $cacheSeconds = $this->getOption('cacheSeconds');
     $lastRefreshed = empty($oldData) ? 0 : strtotime($oldData['tiki_updated']);
     if (!$cacheSeconds || TikiLib::lib('tiki')->now > $lastRefreshed + $cacheSeconds) {
         $ws_params = array();
         $definition = $this->getTrackerDefinition();
         if ($this->getOption('params')) {
             parse_str($this->getOption('params'), $ws_params);
             foreach ($ws_params as $ws_param_name => &$ws_param_value) {
                 if (preg_match('/(.*)%(.*)%(.*)/', $ws_param_value, $matches)) {
                     $ws_param_field_name = $matches[2];
                     $field = $definition->getField($ws_param_field_name);
                     if (!$field) {
                         $field = $definition->getFieldFromName($ws_param_field_name);
                     }
                     if ($field) {
                         $itemData = $this->getItemData();
                         if (isset($itemData[$field['fieldId']])) {
                             $value = TikiLib::lib('trk')->get_field_value($field, $itemData);
                         } else {
                             $itemUser = '';
                             $value = TikiLib::lib('trk')->get_item_fields($definition->getConfiguration('trackerId'), $itemData['itemId'], [$field], $itemUser);
                             $value = isset($value[0]['value']) ? $value[0]['value'] : '';
                         }
                         $ws_params[$ws_param_name] = preg_replace('/%' . $ws_param_field_name . '%/', $value, $ws_param_value);
                     }
                 }
             }
         }
         $response = $webservice->performRequest($ws_params);
         $response->data['tiki_updated'] = gmdate('c');
         if (empty($context['search_render']) || $context['search_render'] !== 'y') {
             $thisField = $definition->getField($this->getConfiguration('fieldId'));
             $thisField['value'] = json_encode($response->data);
             $itemId = TikiLib::lib('trk')->replace_item($definition->getConfiguration('trackerId'), $this->getItemId(), ['data' => [$thisField]]);
             if (!$itemId) {
                 TikiLib::lib('errorreport')->report(tr('Error updating Webservice field %0', $this->getConfiguration('permName')));
                 // try and restore previous data
                 $response->data = json_decode($this->getValue());
             }
         }
     } else {
         $response = OIntegrate_Response::create($oldData, false);
         unlink($template->getTemplateFile());
         $template = $webservice->getTemplate($this->getOption('template'));
     }
     $output = $template->render($response, 'html');
     return $output;
 }
示例#6
0
 // Create new registered service
 if (isset($_REQUEST['new_name'])) {
     $name = $_REQUEST['new_name'];
     if (!empty($name) && !Tiki_Webservice::getService($name)) {
         if ($service = Tiki_Webservice::create($name)) {
             $service->url = $url;
             $service->wstype = $wstype;
             $service->body = $body;
             $service->operation = $operation;
             $service->schemaDocumentation = $response->schemaDocumentation;
             $service->schemaVersion = $response->schemaVersion;
             $service->save();
             $webservice = $service;
         } else {
             TikiLib::lib('errorreport')->report(tr('Webservice error "%0" not saved (alpha characters only)', $name));
             $webservice = new Tiki_Webservice();
             $webservice->url = $url;
             $webservice->wstype = $wstype;
             $webservice->body = $body;
             $webservice->operation = $operation;
             $storedTemplates = array();
         }
     }
 }
 // Save template modification
 if (isset($_REQUEST['nt_name'])) {
     $name = $_REQUEST['nt_name'];
     if (($template = $webservice->getTemplate($name)) || ($template = $webservice->addTemplate($name))) {
         $template->engine = $_REQUEST['nt_engine'];
         $template->output = $_REQUEST['nt_output'];
         $template->content = $_REQUEST['nt_content'];
                $webservice = $service;
            }
        }
    }
    // Save template modification
    if (isset($_REQUEST['nt_name'])) {
        $name = $_REQUEST['nt_name'];
        if (($template = $webservice->getTemplate($name)) || ($template = $webservice->addTemplate($name))) {
            $template->engine = $_REQUEST['nt_engine'];
            $template->output = $_REQUEST['nt_output'];
            $template->content = $_REQUEST['nt_content'];
            $template->save();
            $storedTemplates = $webservice->getTemplates();
        }
    }
    if (isset($_REQUEST['preview']) && ($template = $webservice->getTemplate($_REQUEST['preview']))) {
        $output = $template->render($response, 'html');
        $smarty->assign('preview', $_REQUEST['preview']);
        $smarty->assign('preview_output', $output);
    }
}
$headerlib->add_jsfile('lib/soap/tiki-admin_webservices.js');
$smarty->assign('webservicesTypes', Tiki_Webservice::getTypes());
$smarty->assign('webservices', Tiki_Webservice::getList());
$smarty->assign('storedName', $webservice->getName());
$smarty->assign('storedTemplates', $storedTemplates);
$smarty->assign('url', $webservice->url);
$smarty->assign('postbody', $webservice->body);
$smarty->assign('operation', $webservice->operation);
$smarty->assign('wstype', $webservice->wstype);
$smarty->assign('params', $webservice->getParameterMap($_REQUEST['params']));