src/tools/web/PingBack.php
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));
	}
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));
	}
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 ) ) ; }
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
Receive ping check if local page is pingback - enabled verify source contents and return XML - RPC response