id = $id+0; $this->path = $path; if (!$this->id || !$this->path) return false; if (file_exists($base_path."/admin/connecteurs/out/$path/manifest.xml")) $manifest=$base_path."/admin/connecteurs/out/$path/manifest.xml"; else $manifest=$base_path."/admin/connecteurs/out/$path/manifest.xml"; $this->parse_manifest($manifest); $this->get_messages(); $this->get_config_from_db(); $this->get_sources(); } function get_running_pmb_userid($source_id) { //Par défaut, les connecteurs executent leurs fonctions en admin return 1; } function parse_manifest($filename) { $xml=file_get_contents($filename); $param=_parser_text_no_function_($xml,"MANIFEST"); $this->name = $param["NAME"][0]["value"]; $this->comment = $param["COMMENT"][0]["value"]; $this->author = $param["AUTHOR"][0]["value"]; $this->org = $param["ORG"][0]["value"]; $this->date = $param["DATE"][0]["value"]; $this->url = $param["URL"][0]["value"]; if (isset($param["API_REQUIREMENTS"][0]["REQUIREMENT"])) { foreach ($param["API_REQUIREMENTS"][0]["REQUIREMENT"] as $arequirement) { $this->api_requirements[] = array( "group" => $arequirement["DOMAIN"], "name" => $arequirement["NAME"], "version" => $arequirement["VERSION"] ); } } } function get_messages() { global $lang; global $base_path; $path = $this->path; if (file_exists($base_path."/admin/connecteurs/out/$path/messages/".$lang.".xml")) { $file_name=$base_path."/admin/connecteurs/out/$path/messages/".$lang.".xml"; } else if (file_exists($base_path."/admin/connecteurs/out/$path/messages/fr_FR.xml")) { $file_name=$base_path."/admin/connecteurs/out/$path/messages/fr_FR.xml"; } if ($file_name) { $xmllist=new XMLlist($file_name); $xmllist->analyser(); $this->msg=$xmllist->table; } } function ckeck_api_requirements() { $api_catalog = new es_catalog(); foreach ($this->api_requirements as $arequirement) { //Pas le groupe? NON! if (!isset($api_catalog->groups[$arequirement["group"]])) return false; //Pas la méthode? NON! if (!isset($api_catalog->groups[$arequirement["group"]]->methods[$arequirement["name"]])) return false; //Pas une version suffisante? NON! if ($api_catalog->groups[$arequirement["group"]]->methods[$arequirement["name"]]->version < $arequirement["version"]) return false; //Sinon? OUI! return true; } } function commit_to_db() { global $dbh; $sql = "REPLACE INTO connectors_out SET connectors_out_config = '".addslashes(serialize($this->config))."', connectors_out_id = ".$this->id; mysql_query($sql, $dbh); } function get_config_from_db() { global $dbh; $sql = "SELECT connectors_out_config FROM connectors_out WHERE connectors_out_id = ".$this->id; $res = mysql_query($sql, $dbh); $row = mysql_fetch_assoc($res); $this->config = unserialize($row["connectors_out_config"]); } //Abstraite function get_config_form() { //Rien return ""; } //Abstraite function update_config_from_form() { //Rien return; } function instantiate_source_class($source_id) { return new connecteur_out_source($this, $source_id, $this->msg); } function get_sources() { global $dbh; $sql = "SELECT connectors_out_source_id FROM connectors_out_sources WHERE connectors_out_sources_connectornum = ".$this->id; $res = mysql_query($sql, $dbh); while ($row=mysql_fetch_assoc($res)) { $this->sources[] = $this->instantiate_source_class($row["connectors_out_source_id"]); } } //Cette fonction défini si le connecteur a besoin des messages de /includes/messages/*.xml function need_global_messages() { return true; } //Abstraite function process($source_id, $pmb_user_id) { //Cette fonction correspond au traitement d'une requète sur une source dans le cadre de l'utilisation du connecteur //Rien return; } } function instantiate_connecteur_out($connector_id) { global $base_path; $filename = $base_path."/admin/connecteurs/out/catalog.xml"; $xml=file_get_contents($filename); $param=_parser_text_no_function_($xml,"CATALOG"); foreach ($param["ITEM"] as $anitem) { if ($anitem["ID"] == $connector_id) { $before_eval_vars = get_defined_vars(); require_once $base_path."/admin/connecteurs/out/".$anitem["PATH"]."/".$anitem["PATH"].".class.php"; //Procédure d'extraction de variable: voir http://fr2.php.net/manual/en/language.variables.scope.php#91982 $function_variable_names = array("function_variable_names" => 0, "before_eval_vars" => 0, "created" => 0); $created = array_diff_key(get_defined_vars(), $GLOBALS, $function_variable_names, $before_eval_vars); foreach ($created as $created_name => $on_sen_fiche) global $$created_name; extract($created); $conn = new $anitem["PATH"]($connector_id, $anitem["PATH"]); return $conn; } } return NULL; } class connecteurs_out { var $connectors=array(); function connecteurs_out() { global $base_path; $filename = $base_path."/admin/connecteurs/out/catalog.xml"; $xml=file_get_contents($filename); $param=_parser_text_no_function_($xml,"CATALOG"); foreach ($param["ITEM"] as $anitem) { $this->connectors[] = new connecteur_out($anitem["ID"], $anitem["PATH"]); } } } class connecteur_out_source { var $id; var $connector_id; var $connector; var $name=""; var $comment=""; var $config=""; var $msg=array(); function connecteur_out_source($connector, $id, $msg) { global $dbh; $id+=0; $this->id = $id; $this->connector = $connector; $this->connector_id = $connector->id; $this->msg = $msg; if ($this->id) { $sql = "SELECT * FROM connectors_out_sources WHERE connectors_out_source_id = ".$id; $res = mysql_query($sql, $dbh); $row = mysql_fetch_assoc($res); $this->name = $row["connectors_out_source_name"]; $this->comment = $row["connectors_out_source_comment"]; $this->config = unserialize($row["connectors_out_source_config"]); $this->config = stripslashes_array($this->config); } } function commit_to_db() { if (!$this->id) return; global $dbh; $this->config = addslashes_array($this->config); $serialized = serialize($this->config); $sql = "REPLACE INTO connectors_out_sources SET connectors_out_source_id = ".$this->id.", connectors_out_sources_connectornum = ".$this->connector_id.", connectors_out_source_name='".addslashes($this->name)."', connectors_out_source_comment = '".addslashes($this->comment)."', connectors_out_source_config = '".addslashes($serialized)."'"; mysql_query($sql, $dbh); } static function add_new($connector_id) { global $dbh; $sql = "INSERT INTO connectors_out_sources (connectors_out_sources_connectornum) VALUES (".$connector_id.")"; mysql_query($sql, $dbh); $new_source_id = mysql_insert_id($dbh); $conn = new connecteur_out($connector_id); return new connecteur_out_source($conn, $new_source_id, array()); } static function name_exists($name_to_test) { global $dbh; $sql = "SELECT COUNT(1) FROM connectors_out_sources WHERE connectors_out_source_name = '".addslashes($name_to_test)."'"; $count = mysql_result(mysql_query($sql, $dbh), 0, 0); return $count > 0; } static function get_connector_id($source_id) { global $dbh; $sql = "SELECT connectors_out_sources_connectornum FROM connectors_out_sources WHERE connectors_out_source_id = ".($source_id+0); $res = mysql_query($sql, $dbh); $row = mysql_fetch_array($res); return $row["connectors_out_sources_connectornum"]; } function get_config_form() { global $msg, $charset; //Source name $result = '