Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('../local/config.php');
- require_once('../include/auth.php');
- include('../include/CHILIService.php');
- $apikey = $_SESSION['API_KEY'];
- $chiliservice = new SoapClient('http://'.CHILISERVER.'/chili/Main.asmx?WSDL');
- $searchstring = $_GET['itemID'];
- function insertAnnosOnPage($chiliservice,$apikey,$searchstring) {
- /*
- $username = FOTOWEBUSER;
- $password = FOTOWEBPASSWORD;
- $FWSession = generateFotowebSessionCookie($username,$password);
- // SEARCH
- $searchurl = "http://" . FOTOWEBSERVER . "/fotoweb/fwbin/fotoweb_isapi.dll/ArchiveAgent/" . FOTOWEBBILDEARKIV . "/Search?Search=" . $searchstring . "&MetaData=1&FileInfo=1&PreviewSize=200&MaxHits=" . FOTOWEBMAXHITS . "u=" . FOTOWEBUSER . "&p=" . FOTOWEBPASSWORD;
- */
- // Create a Fotoweb login session cookie
- $FWSession = generateFotowebSessionCookie(FOTOWEBUSER,FOTOWEBPASSWORD);
- //$searchstring = urlencode($_GET['search']);
- $username = FOTOWEBUSER;
- $password = FOTOWEBPASSWORD;
- // Create a Fotoweb login session cookie
- $FWSession = generateFotowebSessionCookie($username,$password);
- if (isset($_GET['debug'])) {
- echo $FWSession;
- }
- $searchurl = "http://" . FOTOWEBSERVER . "/fotoweb/fwbin/fotoweb_isapi.dll/ArchiveAgent/" . FOTOWEBBILDEARKIV . "/Search?Search=" . $searchstring . "&MetaData=1&FileInfo=1&PreviewSize=200&MaxHits=" . FOTOWEBMAXHITS . "&u=" . $username . "&p=" . $password;
- $ch = curl_init($searchurl);
- $timeout = 5;
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- curl_setopt($ch,CURLOPT_COOKIE, "FWSESSION=".$FWSession);
- $data = curl_exec($ch);
- curl_close($ch);
- $theHits = simplexml_load_string($data);
- foreach ($theHits as $hit) {
- $fotowebIDforAnno = (string)$hit['Id'];
- }
- if ($fotowebIDforAnno != "") {
- //echo "/Download?Id=" . $fotowebIDforAnno;
- $url = "http://" . FOTOWEBSERVER . "/fotoweb/fwbin/fotoweb_isapi.dll/ArchiveAgent/" . FOTOWEBBILDEARKIV . "/Download?Id=" . $fotowebIDforAnno . "&NoAttachment=1" . "&u=" . $username . "&p=" . $password;
- // Upload the image and get its new id and name
- //echo "Trying to fetch anno " . $searchstring . "<br>";
- try {
- $assetXML = uploadItemToCHILI($chiliservice,$apikey,$searchstring,'test',$url);
- $ResourceItemGetURLDOM=new SimpleXMLElement($assetXML);
- $xml = $ResourceItemGetURLDOM->asXML();
- $res = $ResourceItemGetURLDOM->xpath("//item/@id");
- $img = $res[0]->id;
- echo $img ;
- // insert Image into chilidoc.
- // strat to get the ID
- } catch (SoapFault $fault) {
- //echo "Anno " . $searchstring . " COULD NOT BE fetched from Fotoweb!<br>";
- //echo $fault;
- }
- } else {
- //echo 'no hits';
- }
- }
- function generateFotowebSessionCookie($u,$p) {
- $loginurl = "http://" . FOTOWEBSERVER . "/fotoweb/cmdrequest/Login.fwx?u=" . $u . "&p=" . $p;
- $ch = curl_init($loginurl);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- preg_match('/^Set-Cookie: (.*?);/m', curl_exec($ch), $m);
- curl_close($ch);
- return substr($m[1],10);
- }
- function uploadItemToCHILI($chiliservice,$apikey,$newitemname,$newitempath,$url) {
- $xml_request = new ResourceItemAddFromURL();
- $xml_request->apiKey = $apikey;
- $xml_request->resourceName = "Assets";
- $xml_request->newName = $newitemname;
- $xml_request->folderPath = $newitempath;
- $xml_request->url = $url;
- $xml_request->login = "";
- $xml_request->pw = "";
- $xml_request->reuseExisting = true;
- $xml_request->previewFileURL = "";
- $xml_request->previewExtension = "";
- $xml_request->isPermanentPreview = false;
- $result = $chiliservice->ResourceItemAddFromURL($xml_request);
- return $result->ResourceItemAddFromURLResult;
- }
- insertAnnosOnPage($chiliservice,$apikey,$searchstring);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement