コード例 #1
0
    function convert_batch_to_oairecords($notices_to_convert, $format, $target_charset)
    {
        global $dbh;
        if (!$notices_to_convert) {
            //Rien à faire? On fait rien
            return;
        }
        //Allons chercher les dates et les statuts des notices
        $notice_datestamps = array();
        $notice_statuts = array();
        $notice_ids = $notices_to_convert;
        //Par paquets de 100 pour ne pas brusquer mysql
        $notice_idsz = array_chunk($notice_ids, 100);
        $iso8601 = new iso8601("YYYY-MM-DDThh:mm:ssZ");
        foreach ($notice_idsz as $anotice_ids) {
            $sql = "SELECT notice_id, UNIX_TIMESTAMP(update_date) AS datestamp, statut FROM notices WHERE notice_id IN (" . implode(",", $anotice_ids) . ")";
            $res = pmb_mysql_query($sql, $dbh);
            while ($row = pmb_mysql_fetch_assoc($res)) {
                $notice_datestamps[$row["notice_id"]] = $iso8601->unixtime_to_iso8601($row["datestamp"]);
                $notice_statuts[$row["notice_id"]] = $row["statut"];
            }
        }
        //Si il existe un status correspondant à la suppression, on génère ces enregistrements et on les supprime de la liste à générer.
        if ($this->deleted_record_statut) {
            $deleted_records = array();
            foreach ($notice_statuts as $notice_id => $anotice_statut) {
                if ($anotice_statut == $this->deleted_record_statut) {
                    $notice_sets = connector_out_set_noticecaddie::get_notice_setlist($notice_id);
                    $notice_sets = array_intersect($notice_sets, $this->source_set_ids);
                    $deleted_records = array('datestamp' => $datestamps[$notice_id], 'sets' => $notice_sets);
                    unset($notices_to_convert[array_search($notice_id, $notices_to_convert)]);
                }
            }
        } else {
            if ($this->deletion_management) {
                $deleted_records = $this->get_deleted_records($this->source_set_ids, $notices_to_convert, $iso8601);
            }
        }
        // On génère les enregistrements supprimés
        foreach ($deleted_records as $notice_id => $deleted_record) {
            $oai_record = "";
            $oai_record .= "<record>";
            $oai_record .= '<header status="deleted">
							<identifier>oai:' . XMLEntities($this->repository_identifier) . ':' . $notice_id . '</identifier>
									<datestamp>' . $deleted_record['datestamp'] . '</datestamp>';
            foreach ($deleted_record['sets'] as $aset_id) {
                $oai_record .= "<setSpec>set_" . $aset_id . "</setSpec>";
            }
            $oai_record .= '</header>';
            $oai_record .= "</record>";
            $this->results[$notice_id] = $oai_record;
        }
        //Convertissons les notices au format demandé si on ne souhaite pas uniquement les entêtes
        $only_identifier = $format == "__oai_identifier";
        if (!$only_identifier) {
            $converter = new external_services_converter_notices(1, $this->set_life_duration);
            $converter->params["include_items"] = $this->include_items;
            $converter->params["include_links"] = $this->include_links;
            $metadatas = $converter->convert_batch($notices_to_convert, $format, $target_charset, $this->xslt);
        }
        //Fabriquons les enregistrements
        foreach ($notices_to_convert as $notice_id) {
            $notice_sets = connector_out_set_noticecaddie::get_notice_setlist($notice_id);
            $notice_sets = array_intersect($notice_sets, $this->source_set_ids);
            $oai_record = "";
            if (!$only_identifier) {
                $oai_record .= "<record>";
            }
            $oai_record .= '<header>
					<identifier>oai:' . XMLEntities($this->repository_identifier) . ':' . $notice_id . '</identifier>
							<datestamp>' . $notice_datestamps[$notice_id] . '</datestamp>';
            foreach ($notice_sets as $aset_id) {
                $oai_record .= "<setSpec>set_" . $aset_id . "</setSpec>";
            }
            $oai_record .= '</header>';
            if (!$only_identifier) {
                $oai_record .= "<metadata>";
                $oai_record .= $metadatas[$notice_id];
                $oai_record .= "</metadata>";
            }
            if (!$only_identifier) {
                $oai_record .= "</record>";
            }
            $this->results[$notice_id] = $oai_record;
        }
    }
コード例 #2
0
ファイル: test.php プロジェクト: jankichaudhari/yii-site
<?php

function XMLEntities($string)
{
    $string = preg_replace('/[^\\x09\\x0A\\x0D\\x20-\\x7F]/e', '_privateXMLEntities("$0")', $string);
    return $string;
}
function _privateXMLEntities($num)
{
    $chars = array(128 => '&#8364;', 130 => '&#8218;', 131 => '&#402;', 132 => '&#8222;', 133 => '&#8230;', 134 => '&#8224;', 135 => '&#8225;', 136 => '&#710;', 137 => '&#8240;', 138 => '&#352;', 139 => '&#8249;', 140 => '&#338;', 142 => '&#381;', 145 => '&#8216;', 146 => '&#8217;', 147 => '&#8220;', 148 => '&#8221;', 149 => '&#8226;', 150 => '&#8211;', 151 => '&#8212;', 152 => '&#732;', 153 => '&#8482;', 154 => '&#353;', 155 => '&#8250;', 156 => '&#339;', 158 => '&#382;', 159 => '&#376;');
    $num = ord($num);
    return $num > 127 && $num < 160 ? $chars[$num] : "&#" . $num . ";";
}
$string = '<p>&Eacute; Having recently undergone a precise and positive refurbishment, this two double bedroom apartment has an immaculate interior, lots of living space and still retains some original features. It sits above commercial premises on Streatham High Road - famous for its abundant shopping parade and buzzing transport options.</p><p>Gain entry by walking along a cleverly hidden passage on Norfolk House Road (a residential side street running of Streatham High Road). You enter at the rear of the building, where a communal iron staircase will lead you up to the first floor. Nip through the communal hallway and up to the second floor to your flat. Gorgeous wooden floors run underfoot and continue into the bedrooms and the reception. Your first stop toward the front of the property is the reception room; it&#039;s a good size with two sash windows, a feature chimney breast and those signature brilliant-white walls. A swanky bathroom sits just next door. It has a pristine white suite including shower attachment, frosted sash window and attractive wall tiles up to picture rail level. Both bedrooms are good size doubles and the separate kitchen is large enough to fulfill your culinary desires. Find an integrated oven, four ring has hob, masses of wooden cabinets and black work surfaces too.</p><p>Take care of the commute at nearby Streatham Hill station (Victoria) which is within a 10 minute walk from your door. If you&#039;d rather travel into London Bridge, then walk a little further in the other direction and use Streatham station. Buses aplenty whizz along Streatham High Street, for around-the-clock trips into town. Believed to be the longest High Street in the country, you couldn&#039;t possibly be bored! There&#039;s a cinema, bowling centre and ice rink plus many good places to eat. Neighbouring Brixton and Crystal Palace offer many more nightspots, restaurants and bars. Take the Sunday papers to beautiful Tooting Bec Common, a short stroll away.</p>';
echo XMLEntities($string);
コード例 #3
0
    function return_wsdl($source_object, $user_id = 0)
    {
        global $charset;
        global $declared_types;
        global $type_aliases;
        $cache_ref = "api_soap_wsdl_" . $source_object->id;
        if ($source_object->connector->config["cache_wsdl"]) {
            //Voyons si on peut trouver quelque chose de pas trop vieux dans le cache
            $es_cache = new external_services_cache('es_cache_blob', 3600);
            $cached_result = $es_cache->decache_single_object($cache_ref, CACHE_TYPE_MISC);
            if ($cached_result !== false) {
                //Il est bon? On l'envoi
                if (!isset($_GET["nx"])) {
                    header('Content-Type: text/xml');
                }
                print $cached_result;
                exit;
            }
        }
        //Récupérons la liste des fonctions que l'on doit exporter
        $api_catalog = new es_catalog();
        $api_es = new external_services();
        //$api_rights = new external_services_rights($api_es);
        $final_method_list = array();
        foreach ($source_object->config["exported_functions"] as $amethod) {
            //		if ($api_rights->has_rights($user_id, $amethod["group"], $amethod["name"])) {
            $final_method_list[] = $amethod;
            //		}
        }
        //Les entêtes du fichier
        $wsdl_headers = '<?xml version="1.0" encoding="UTF-8"?>
		<?xml-stylesheet type="text/xsl" href="connecteurs/out/apisoap/wsdl-viewer.xsl"?>
		<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://sigb.net/pmb/es/apisoap" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PMBSOAPAPI" targetNamespace="http://sigb.net/pmb/es/apisoap">';
        //Les entêtes des déclaration de type
        $wsdl_types = '<wsdl:types>
		    <xsd:schema targetNamespace="http://sigb.net/pmb/es/apisoap" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
		    	<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>';
        //On va construire la liste des types à déclarer en fonction de ce que l'on va rencontrer, puis on y reviendra
        $additional_definitions = array();
        $declared_types = array();
        $type_aliases = array();
        //Ajoutons les types du manifest s'il y en a
        $handled_groups = array();
        foreach ($final_method_list as $amethod) {
            //Vérifions si on a pas déjà traité les types de ce groupe
            if (isset($handled_groups[$amethod["group"]])) {
                continue;
            }
            //Ajoutons les types du groupe de la methode courante
            foreach ($api_catalog->groups[$amethod["group"]]->types as &$atype) {
                if ($atype->imported) {
                    $base_name = $api_catalog->groups[$atype->imported_from]->name . '_' . $atype->name;
                    $local_base_name = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->group . '_' . $atype->name;
                    if (isset($declared_types[$base_name])) {
                        if (!isset($type_aliases[$local_base_name])) {
                            $type_aliases[$local_base_name] = $base_name;
                        }
                        continue;
                    }
                    $this->type_to_wsdl($api_catalog->groups[$atype->imported_from]->types[$atype->name], $base_name, $atype->imported_from, $additional_definitions, "element");
                    $type_aliases[$local_base_name] = $base_name;
                } else {
                    $base_name = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->group . '_' . $atype->name;
                    if (isset($declared_types[$base_name])) {
                        continue;
                    }
                    $this->type_to_wsdl($atype, $base_name, $amethod["group"], $additional_definitions, "element");
                }
                $declared_types[$base_name] = true;
            }
            $handled_groups[$amethod["group"]] = true;
        }
        //Construction des messages
        $wsdl_messages = "";
        foreach ($final_method_list as $amethod) {
            $method_name = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->group . '_' . $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->name;
            $wsdl_messages .= '<wsdl:message name="' . XMLEntities($method_name) . 'Request">';
            foreach ($api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->inputs as $ainput) {
                $wsdl_messages .= $this->input_to_wsdl($ainput, $method_name, $amethod["group"], $additional_definitions, "part");
            }
            $wsdl_messages .= '</wsdl:message>';
            $wsdl_messages .= '<wsdl:message name="' . XMLEntities($method_name) . 'Response">';
            $output_count = count($api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->outputs);
            if ($output_count > 1) {
                $additional_definition = "";
                $additional_definition .= '<xsd:complexType name="' . XMLEntities($method_name) . 'ResponseStruct">';
                $additional_definition .= '<xsd:sequence>';
                foreach ($api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->outputs as $ainput) {
                    $additional_definition .= $this->output_to_wsdl($ainput, $method_name, $amethod["group"], $additional_definitions, "element");
                }
                $additional_definition .= '</xsd:sequence>';
                $additional_definition .= '</xsd:complexType>';
                $additional_definitions[XMLEntities($method_name) . 'ResponseStruct'] = $additional_definition;
                $wsdl_messages .= '<wsdl:part name="result" type="tns:' . XMLEntities($method_name) . 'ResponseStruct"/>';
            } else {
                if ($output_count) {
                    $wsdl_messages .= $this->output_to_wsdl($api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->outputs[0], $method_name, $amethod["group"], $additional_definitions, "part");
                }
            }
            $wsdl_messages .= '</wsdl:message>';
        }
        //On a maintenant les types, on fini de construire le bloc associé
        $wsdl_types .= implode("", $additional_definitions);
        $wsdl_types .= '</xsd:schema>
		     	</wsdl:types>';
        //PortType
        $wsdl_porttype = "";
        $wsdl_porttype .= '<wsdl:portType name="PMBSOAPAPI">';
        foreach ($final_method_list as $amethod) {
            $method_name = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->group . '_' . $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->name;
            $method_group = $amethod["group"];
            $method_description = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->description;
            $input_description = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->input_description;
            $output_description = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->output_description;
            $wsdl_porttype .= '
			       <wsdl:operation name="' . XMLEntities($method_name) . '">
	                 <wsdl:documentation>' . XMLEntities($api_es->get_text($method_description, $method_group)) . '</wsdl:documentation>
			         <wsdl:input message="tns:' . XMLEntities($method_name) . 'Request">
			           <wsdl:documentation>' . XMLEntities($api_es->get_text($input_description, $method_group)) . '</wsdl:documentation>
			         </wsdl:input>
			         <wsdl:output message="tns:' . XMLEntities($method_name) . 'Response">
			           <wsdl:documentation>' . XMLEntities($api_es->get_text($output_description, $method_group)) . '</wsdl:documentation>
			         </wsdl:output>
			       </wsdl:operation>';
        }
        $wsdl_porttype .= '</wsdl:portType>';
        //Binding
        $wsdl_binding = "";
        $wsdl_binding .= '<wsdl:binding name="PMBSOAPAPI_Binding" type="tns:PMBSOAPAPI">
			    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>';
        foreach ($final_method_list as $amethod) {
            $method_name = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->group . '_' . $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->name;
            $wsdl_binding .= '
				   <wsdl:operation name="' . XMLEntities($method_name) . '">
				      <soap:operation soapAction="http://sigb.net/pmb/es/apisoap/' . XMLEntities($method_name) . '" style="rpc"/>
				      <wsdl:input>
 			            <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded" />
  				      </wsdl:input>
				      <wsdl:output>
				        <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded" />
				      </wsdl:output>
				   </wsdl:operation>';
        }
        $wsdl_binding .= '</wsdl:binding>';
        //Service
        $server_location = serverURL();
        $wsdl_service = "";
        $wsdl_service .= '
	  <wsdl:service name="PMBSOAPAPI">
	    <wsdl:port binding="tns:PMBSOAPAPI_Binding" name="PMBSOAPAPI">
	      <soap:address location="' . XMLEntities($server_location) . '"/>
	    </wsdl:port>
	  </wsdl:service>';
        $wsdl_footer = '</wsdl:definitions>';
        //On conbine le tout pour donner le wsdl final
        $wsdl = $wsdl_headers . $wsdl_types . $wsdl_messages . $wsdl_porttype . $wsdl_binding . $wsdl_service . $wsdl_footer;
        if ($charset != 'utf-8') {
            $wsdl = utf8_encode($wsdl);
        }
        //On le met en cache si on le souhaite
        if ($source_object->connector->config["cache_wsdl"]) {
            $es_cache = new external_services_cache('es_cache_blob', 600);
            $es_cache->encache_single_object($cache_ref, CACHE_TYPE_MISC, $wsdl);
        }
        //Et on l'envoi
        if (!isset($_GET["nx"])) {
            header('Content-Type: text/xml');
        }
        print $wsdl;
        exit;
    }