/** * dispatch * * Analyse the GET string and call the correct function * * @return the xml to be sent to the client */ function dispatch() { global $active_entities ; if (!isset($_GET['entity']) or ($_GET['entity'] == '')) { internal_error('Entity parameter not defined in request') ; } $entity = sanitize_param($_GET['entity']) or internal_error('sanitizing error') ; if (!in_array($entity, $active_entities)) { internal_error('Unknown entity "'.$entity.'"') ; } // default action $action = 'list' ; // search (RESTfull way does not like verbs in url, but complex search is usefull...) if (isset($_GET['action']) and ($_GET['action'] == 'search')) { unset($_GET['entity']) ; unset($_GET['action']) ; $action = 'search' ; } // detail if ((isset($_GET['entity_id'])) and ($_GET['entity_id'] != 0)) { $action = 'detail' ; } $func = 'get_'.$entity.'_'.$action ; if (!function_exists($func)) { internal_error("Can't find function ".sanitize_param($func)) ; } return $func() ; }
/** * Get's the current post's post_type. */ public function get_current_post_type() { global $post, $typenow, $current_screen; if (!empty($post) && !empty($post->post_type)) { //we have a post so we can just get the post type from that $type = $post->post_type; } elseif (!empty($typenow)) { //check the global $typenow - set in admin.php $type = $typenow; } elseif (!empty($current_screen) && !empty($current_screen->post_type)) { //check the global $current_screen object - set in sceen.php $type = $current_screen->post_type; } elseif (isset($_REQUEST['post_type'])) { //lastly check the post_type querystring $type = $_REQUEST['post_type']; sanitize_param($type); } else { $type = null; } return $type; }
/** * get_contact_detail * * return string XML representation of one contact */ function get_contact_detail() { // get sql datas $datas = get_contact_detail_by_id(sanitize_param($_GET['entity_id'])) ; // if no datas, return if (count($datas) == 0) { return ; } // else // create xml doc $xml_doc = new DOMDocument('1.0', 'UTF-8') ; // create contact node $entity_node = $xml_doc->createElement('contact') ; $xml_doc->appendChild($entity_node) ; // foreach data, create xml node, add it to contact node foreach ($datas as $data) { foreach ($data as $name => $value) { $new_node = $xml_doc->createElement($name, utf8_encode(htmlspecialchars($value, ENT_COMPAT))) ; $entity_node->appendChild($new_node) ; } } // return xml doc $xml_string = $xml_doc->saveXML() ; return $xml_string ; }