/** * Receive ping, check if local page is pingback-enabled, verify * source contents, and return XML-RPC response * @return string * @param $func callback * @param $path string **/ function listen($func, $path = NULL) { $fw = \Base::instance(); if (PHP_SAPI != 'cli') { header('X-Powered-By: ' . $fw->get('PACKAGE')); header('Content-Type: application/xml; ' . 'charset=' . ($charset = $fw->get('ENCODING'))); } if (!$path) { $path = $fw->get('BASE'); } $web = \Web::instance(); $args = xmlrpc_decode_request($fw->get('BODY'), $method, $charset); $options = array('encoding' => $charset); if ($method == 'pingback.ping' && isset($args[0], $args[1])) { list($source, $permalink) = $args; $doc = new \DOMDocument('1.0', $fw->get('ENCODING')); // Check local page if pingback-enabled $parts = parse_url($permalink); if ((empty($parts['scheme']) || $parts['host'] == $fw->get('HOST')) && preg_match('/^' . preg_quote($path, '/') . '/' . ($fw->get('CASELESS') ? 'i' : ''), $parts['path']) && $this->enabled($permalink)) { // Check source $parts = parse_url($source); if ((empty($parts['scheme']) || $parts['host'] == $fw->get('HOST')) && ($req = $web->request($source)) && $doc->loadhtml($req['body'])) { $links = $doc->getelementsbytagname('a'); foreach ($links as $link) { if ($link->getattribute('href') == $permalink) { call_user_func_array($func, array($source, $req['body'])); // Success die(xmlrpc_encode_request(NULL, $source, $options)); } } // No link to local page die(xmlrpc_encode_request(NULL, 0x11, $options)); } // Source failure die(xmlrpc_encode_request(NULL, 0x10, $options)); } // Doesn't exist (or not pingback-enabled) die(xmlrpc_encode_request(NULL, 0x21, $options)); } // Access denied die(xmlrpc_encode_request(NULL, 0x31, $options)); }
public function infusionsoft_subscribe($list_id, $email, $name = null) { // Include WordPress libraries to handle XML-RPC require_once ABSPATH . '/wp-includes/class-IXR.php'; require_once ABSPATH . '/wp-includes/class-wp-http-ixr-client.php'; // get options $options = get_option('optinoid_options'); // Initialize the client $client = new WP_HTTP_IXR_Client('https://' . $options['infusionsoft_subdomain'] . '.infusionsoft.com/api/xmlrpc'); $first_name = null; $last_name = null; if (!empty($name)) { $name_arr = explode(' ', $name); if (!empty($name_arr[0])) { $first_name = $name_arr[0]; } if (!empty($name_arr[1])) { $last_name = $name_arr[1]; } } $client->query('WebFormService.getHTML', $options['infusionsoft_api'], $list_id); $dom = new DOMDocument(); $dom->loadHTML($client->getResponse()); $inputs = $dom->getelementsbytagname('input'); $data = array(); foreach ($inputs as $input) { $name = $input->getAttribute('name'); if ($name == 'inf_field_Email') { $data[$name] = $email; } elseif ($name == 'inf_field_FirstName') { $data[$name] = $first_name; } elseif ($name == 'inf_field_LastName') { $data[$name] = $last_name; } else { $data[$name] = $input->getAttribute('value'); } } $endpoint = 'https://' . $options['infusionsoft_subdomain'] . '.infusionsoft.com/app/form/process/' . $data['inf_form_xid']; $response = wp_remote_post($endpoint, array('body' => $data)); }