public static function getResultFromFunctionParams($rawparams, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $showmode = false)
 {
     SMWSPARQLQueryProcessor::processFunctionParams($rawparams, $querystring, $params, $printouts, $showmode);
     return SMWSPARQLQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI, $context);
 }
예제 #2
0
function smwf_qi_QIAccess($method, $params)
{
    $p_array = explode(",", $params);
    global $smwgQEnabled;
    if ($method == "getPropertyInformation") {
        return qiGetPropertyInformation($p_array[0]);
    } else {
        if ($method == "getPropertyTypes") {
            $p_array = func_get_args();
            $types = "<propertyTypes>";
            for ($i = 1; $i < count($p_array); $i++) {
                $types .= qiGetPropertyInformation($p_array[$i]);
            }
            $types .= "</propertyTypes>";
            return $types;
        } else {
            if ($method == "getNumericTypes") {
                $numtypes = array();
                $types = SMWDataValueFactory::getKnownTypeLabels();
                foreach ($types as $v) {
                    $id = SMWDataValueFactory::findTypeID($v);
                    if (SMWDataValueFactory::newTypeIDValue($id)->isNumeric()) {
                        array_push($numtypes, strtolower($v));
                    }
                }
                return implode(",", $numtypes);
            } else {
                if ($method == "getQueryResult") {
                    $result = "null";
                    if ($smwgQEnabled) {
                        // read fix parameters from QI GUI
                        $params = count($p_array) > 1 ? explode("|", $p_array[1]) : array();
                        $fixparams = array();
                        foreach ($params as $p) {
                            if (strlen($p) > 0 && strpos($p, "=") !== false) {
                                list($key, $value) = explode("=", $p);
                                $fixparams[trim($key)] = str_replace('%2C', ',', $value);
                            }
                        }
                        // indicate that it comes from an ajax call
                        $fixparams['ajaxCall'] = true;
                        // fix bug 10812: if query string contains a ,
                        $p_array[0] = str_replace('%2C', ',', $p_array[0]);
                        // read query with printouts and (possibly) other parameters like sort, order, limit, etc...
                        $pos = strpos($p_array[0], "|?");
                        if ($pos > 0) {
                            $rawparams[] = trim(substr($p_array[0], 0, $pos));
                            $ps = explode("|?", trim(substr($p_array[0], $pos + 2)));
                            foreach ($ps as $param) {
                                $rawparams[] = "?" . trim($param);
                            }
                        } else {
                            $ps = preg_split('/[^\\|]{1}\\|{1}(?!\\|)/s', $p_array[0]);
                            if (count($ps) > 1) {
                                // last char of query condition is missing (matched with [^\|]{1}) therefore copy from original
                                $rawparams[] = trim(substr($p_array[0], 0, strlen($ps[0]) + 1));
                                array_shift($ps);
                                // remove the query condition
                                // add other params for formating etc.
                                foreach ($ps as $param) {
                                    $rawparams[] = trim($param);
                                }
                            } else {
                                $rawparams[] = trim($p_array[0]);
                            }
                        }
                        $rawparams = array_merge($rawparams, $fixparams);
                        // set some default values, if params are not set
                        if (!in_array('reasoner', array_keys($fixparams))) {
                            $fixparams['reasoner'] = 'ask';
                        }
                        if (!in_array('format', array_keys($fixparams))) {
                            $fixparams['format'] = 'table';
                        }
                        // use SMW classes or TSC classes and parse params and answer query
                        if ($fixparams['reasoner'] == 'ask') {
                            SMWQueryProcessor::processFunctionParams($rawparams, $querystring, $params, $printouts);
                        } else {
                            if ($fixparams['reasoner'] == 'sparql') {
                                SMWSPARQLQueryProcessor::processFunctionParams($rawparams, $querystring, $params, $printouts);
                            }
                        }
                        // check if there is any result and if it corresponds to the selected format
                        $mainlabel = isset($rawparams['mainlabel']) && $rawparams['mainlabel'] == '-';
                        $invalidRes = smwf_qi_CheckValidResult($printouts, $fixparams['format'], $mainlabel);
                        if ($invalidRes != 0) {
                            return wfMsg('smw_qi_printout_err' . $invalidRes);
                        }
                        // quickfix: unset conflicting params for maps
                        if (in_array($fixparams['format'], array("map", "googlemaps2", "openlayers", "yahoomaps"))) {
                            if (isset($params['reasoner'])) {
                                unset($params['reasoner']);
                            }
                            if (isset($params['ajaxcall'])) {
                                unset($params['ajaxcall']);
                            }
                            if (isset($params['merge'])) {
                                unset($params['merge']);
                            }
                        }
                        // answer query using the SMW classes or TSC classes
                        if ($fixparams['reasoner'] == 'ask') {
                            $result = SMWQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI);
                        } else {
                            if ($fixparams['reasoner'] == 'sparql') {
                                $result = SMWSPARQLQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI);
                            }
                        }
                        // check for empty result
                        if (is_array($result) && trim($result[0]) == '' || trim($result == '')) {
                            return wfMsg('smw_qi_printout_err4');
                        }
                        switch ($fixparams['format']) {
                            case 'timeline':
                            case 'exhibit':
                            case 'eventline':
                                return $result;
                                break;
                            case 'gallery':
                            case 'googlepie':
                            case 'googlebar':
                            case 'ofc-pie':
                            case 'ofc-bar':
                            case 'ofc-bar_3d':
                            case 'ofc-line':
                            case 'ofc-scatterline':
                                return is_array($result) ? $result[0] : $result;
                                break;
                            case 'map':
                            case 'googlemaps2':
                            case 'openlayers':
                            case 'yahoomaps':
                                return wfMsg('smw_qi_printout_notavailable');
                            default:
                        }
                        $result = parseWikiText($result);
                        // add target="_new" for all links
                        $pattern = "|<a|i";
                        $result = preg_replace($pattern, '<a target="_new"', $result);
                        return $result;
                    }
                } else {
                    if ($method == "getQueryResultForDownload") {
                        $result = "null";
                        if ($smwgQEnabled) {
                            $params = array('format' => $p_array[1], 'link' => $p_array[2], 'intro' => $p_array[3], 'sort' => $p_array[4], 'limit' => $p_array[5], 'mainlabel' => $p_array[6], 'order' => $p_array[7], 'default' => $p_array[8], 'headers' => $p_array[9]);
                            $result = applyQueryHighlighting($p_array[0], $params);
                            // add target="_new" for all links
                            $pattern = "|<a|i";
                            $result = preg_replace($pattern, '<a target="_new"', $result);
                        }
                        if ($result != "null" && $result != "") {
                            global $request_query;
                            $request_query = true;
                        }
                        return $result;
                    } else {
                        if ($method == "getSupportedParameters") {
                            global $smwgResultFormats;
                            wfLoadExtensionMessages('SemanticMediaWiki');
                            $format = $p_array[0];
                            if (array_key_exists($format, $smwgResultFormats)) {
                                $formatclass = $smwgResultFormats[$format];
                            } else {
                                $formatclass = "SMWListResultPrinter";
                            }
                            // fix for missing parameter order
                            $order_missing = true;
                            $intro_missing = true;
                            $outro_missing = true;
                            $qp = new $formatclass($format, false);
                            $params = $qp->getParameters();
                            // repair some misplaced parameters
                            for ($i = 0; $i < count($params); $i++) {
                                switch ($params[$i]['name']) {
                                    case "order":
                                        $order_missing = false;
                                        break;
                                    case "template":
                                        if ($format != "template") {
                                            array_splice($params, $i, 1);
                                        }
                                        break;
                                    case "intro":
                                        if (substr($format, 0, 4) != "ofc-") {
                                            $intro_missing = false;
                                        }
                                        break;
                                    case "outro":
                                        if (substr($format, 0, 4) != "ofc-") {
                                            $outro_missing = false;
                                        }
                                        break;
                                    case "headers":
                                        if ($format != "table" && $format != "broadtable") {
                                            array_splice($params, $i, 1);
                                        }
                                        break;
                                }
                            }
                            if ($order_missing) {
                                $params[] = array('name' => 'order', 'type' => 'enumeration', 'description' => wfMsg('smw_qi_tt_order'), 'values' => array('ascending', 'descending'));
                            }
                            if ($intro_missing) {
                                $params[] = array('name' => 'intro', 'type' => 'string', 'description' => wfMsg('smw_qi_tt_intro'));
                            }
                            if ($outro_missing) {
                                $params[] = array('name' => 'outro', 'type' => 'string', 'description' => wfMsg('smw_qi_tt_outro'));
                            }
                            $jsonEnc = new Services_JSON();
                            return $jsonEnc->encode($params);
                        } else {
                            return "false";
                        }
                    }
                }
            }
        }
    }
}