예제 #1
0
/**
 * Will echo an XML document containing all the resources for a given tag
 *
 * @param STRING $Plugin pluginname
 * @param TAG $Tag tag object
 * @param TagontoNET $tnet
 */
function tagRes($tnet, $tag, $Plugin = "")
{
    global $RESTMESSAGES;
    if (!empty($Plugin) && !in_array($Plugin, $tnet->getPluginListArray())) {
        generateErrorAndDie($RESTMESSAGES['PLUGIN_NOT_FOUND_ERROR'], $RESTMESSAGES['ERROR_LEVEL_FATAL']);
    }
    $Res = $tnet->getResourcesForTag($tag, $Plugin);
    //TODO no results!
    if (empty($Res)) {
        generateErrorAndDie($RESTMESSAGES['NO_RESULT_FOUND']);
    }
    //Creating the XML and outputting
    $doc = new DomDocument('1.0');
    $doc->preserveWhiteSpace = false;
    $doc->formatOutput = true;
    $root = $doc->createElement('tagonto');
    $root->setAttribute('requestSatisfied', 'true');
    $root = $doc->appendChild($root);
    if (!empty($Res)) {
        foreach ($Res as $Risorsa) {
            $risorsa = $doc->createElement('resource');
            $risorsa = $root->appendChild($risorsa);
            //Name
            $child = $doc->createElement('name');
            $child = $risorsa->appendChild($child);
            $value = $doc->createTextNode($Risorsa->getTitle());
            $value = $child->appendChild($value);
            //Url
            $child = $doc->createElement('url');
            $child = $risorsa->appendChild($child);
            $value = $doc->createTextNode($Risorsa->getHomeUrl());
            $value = $child->appendChild($value);
            //Logo
            $child = $doc->createElement('logo');
            $child = $risorsa->appendChild($child);
            $value = $doc->createTextNode($Risorsa->getLogo());
            $value = $child->appendChild($value);
            //Now, results
            $result = $doc->createElement('results');
            $result = $risorsa->appendChild($result);
            $tempresforchecks = $Risorsa->getResults();
            if (!empty($tempresforchecks)) {
                foreach ($Risorsa->getResults() as $Risultato) {
                    $singolorisultato = $doc->createElement('result');
                    $singolorisultato = $result->appendChild($singolorisultato);
                    //Creating results
                    //URL
                    $child = $doc->createElement('url');
                    $child = $singolorisultato->appendChild($child);
                    $value = $doc->createTextNode($Risultato->getUrl());
                    $value = $child->appendChild($value);
                    //SHOWN CONTENT
                    $child = $doc->createElement('showncontent');
                    $child = $singolorisultato->appendChild($child);
                    $value = $doc->createTextNode($Risultato->getShownContent());
                    $value = $child->appendChild($value);
                    //TITLE
                    $child = $doc->createElement('title');
                    $child = $singolorisultato->appendChild($child);
                    $value = $doc->createTextNode($Risultato->getTitle());
                    $value = $child->appendChild($value);
                    //DESC
                    $child = $doc->createElement('desc');
                    $child = $singolorisultato->appendChild($child);
                    $value = $doc->createTextNode($Risultato->getDescription());
                    $value = $child->appendChild($value);
                    //TYPE
                    $child = $doc->createElement('type');
                    $child = $singolorisultato->appendChild($child);
                    $value = $doc->createTextNode($Risultato->getContentType());
                    $value = $child->appendChild($value);
                }
            }
        }
    }
    //Output xml
    $xml_string = $doc->saveXML();
    echo $xml_string;
}
예제 #2
0
 function getResourceResultsByTag($tag)
 {
     $TagontoNET = new TagontoNET();
     $resources = $TagontoNET->getResourcesForTag($tag);
     return $resources;
 }