public function getLicenseXml( $type, $copyright_holder, $src_url, $title, $lang = '', $year = 0 ) {

		$endpoint = 'https://api.creativecommons.org/rest/1.5/';
		$lang = ( ! empty( $lang ) ) ? substr( $lang, 0, 2 ) : '';
		$expected = $this->getSupportedTypes();

		if ( ! array_key_exists( $type, $expected ) ) {
			// nothing meaningful to hit the api with, so bail
			return '';
		}
		if ( $type !== 'all-rights-reserved' && empty( $expected[ $type ]['api'] ) ) {
			// We don't know what to do with a custom license, use "all-rights-reserved" for now
			$type = 'all-rights-reserved';
		}

		switch ( $type ) {
			// api doesn't have an 'all-rights-reserved' endpoint, so manual build necessary
			case 'all-rights-reserved':
				$xml =
					'<result><html>' .
					"<span property='dct:title'>" . Sanitize\sanitize_xml_attribute( $title ) . '</span> ' . __( 'Copyright', 'pressbooks' ) . ' &#169; ';
				if ( $year ) {
					$xml .= Sanitize\sanitize_xml_attribute( $year ) . ' ' . __( 'by', 'pressbooks' ) . ' ';
				}
				$xml .= Sanitize\sanitize_xml_attribute( $copyright_holder );
				$xml .= '. ' . __( 'All Rights Reserved', 'pressbooks' ) . '.</html></result>';
				break;

			default:
				$key = array_keys( $expected[ $type ]['api'] );
				$val = array_values( $expected[ $type ]['api'] );

				$url =
					$endpoint . $key[0] . '/' . $val[0] . '/get?' . $key[1] . '=' . $val[1] . '&' . $key[2] . '=' . $val[2] .
					'&creator=' . rawurlencode( $copyright_holder ) . '&attribution_url=' . rawurlencode( $src_url ) . '&title=' . rawurlencode( $title ) . '&locale=' . $lang;
				if ( $year ) {
					$url .= '&year=' . (int) $year;
				}

				$xml = wp_remote_get( $url );
				$ok = wp_remote_retrieve_response_code( $xml );

				if ( absint( $ok ) === 200 && is_wp_error( $xml ) === false ) {
					$xml = $xml['body'];
				} else {
					// Something went wrong, try to log it
					if ( is_wp_error( $xml ) ) {
						$error_message = $xml->get_error_message();
					} elseif ( is_array( $xml ) && ! empty( $xml['body'] ) ) {
						$error_message = wp_strip_all_tags( $xml['body'] );
					} else {
						$error_message = 'An unknown error occurred';
					}
					debug_error_log( '\Pressbooks\Licensing::getLicenseXml() error: ' . $error_message );
					$xml = ''; // Set empty string
				}
				break;
		}

		return $xml;
	}
public function getLicenseXml( $type, $copyright_holder, $src_url, $title, $lang = '', $year = 0 ) {

		$endpoint = 'https://api.creativecommons.org/rest/1.5/';
		$lang = ( ! empty( $lang ) ) ? substr( $lang, 0, 2 ) : '';
		$expected = $this->getSupportedTypes();

		if ( ! array_key_exists( $type, $expected ) ) {
			// nothing meaningful to hit the api with, so bail
			return '';
		}
		if ( $type !== 'all-rights-reserved' && empty( $expected[ $type ]['api'] ) ) {
			// We don't know what to do with a custom license, use "all-rights-reserved" for now
			$type = 'all-rights-reserved';
		}

		switch ( $type ) {
			// api doesn't have an 'all-rights-reserved' endpoint, so manual build necessary
			case 'all-rights-reserved':
				$xml =
					'<result><html>' .
					"<span property='dct:title'>" . Sanitize\sanitize_xml_attribute( $title ) . '</span> ' . __( 'Copyright', 'pressbooks' ) . ' &#169; ';
				if ( $year ) {
					$xml .= Sanitize\sanitize_xml_attribute( $year ) . ' ' . __( 'by', 'pressbooks' ) . ' ';
				}
				$xml .= Sanitize\sanitize_xml_attribute( $copyright_holder );
				$xml .= '. ' . __( 'All Rights Reserved', 'pressbooks' ) . '.</html></result>';
				break;

			default:
				$key = array_keys( $expected[ $type ]['api'] );
				$val = array_values( $expected[ $type ]['api'] );

				$url =
					$endpoint . $key[0] . '/' . $val[0] . '/get?' . $key[1] . '=' . $val[1] . '&' . $key[2] . '=' . $val[2] .
					'&creator=' . rawurlencode( $copyright_holder ) . '&attribution_url=' . rawurlencode( $src_url ) . '&title=' . rawurlencode( $title ) . '&locale=' . $lang;
				if ( $year ) {
					$url .= '&year=' . (int) $year;
				}

				$xml = wp_remote_get( $url );
				$ok = wp_remote_retrieve_response_code( $xml );

				if ( absint( $ok ) === 200 && is_wp_error( $xml ) === false ) {
					$xml = $xml['body'];
				} else {
					// Something went wrong, try to log it
					if ( is_wp_error( $xml ) ) {
						$error_message = $xml->get_error_message();
					} elseif ( is_array( $xml ) && ! empty( $xml['body'] ) ) {
						$error_message = wp_strip_all_tags( $xml['body'] );
					} else {
						$error_message = 'An unknown error occurred';
					}
					debug_error_log( '\Pressbooks\Licensing::getLicenseXml() error: ' . $error_message );
					$xml = ''; // Set empty string
				}
				break;
		}

		return $xml;
	}
public function getLicenseXml ( $ type , $ copyright_holder , $ src_url , $ title , $ lang = '' , $ year = 0 ) { $ endpoint = 'https://api.creativecommons.org/rest/1.5/' ; $ lang = ( ! empty ( $ lang ) ) ? substr ( $ lang , 0 , 2 ) : '' ; $ expected = $ this -> getSupportedTypes ( ) ; if ( ! array_key_exists ( $ type , $ expected ) ) { // nothing meaningful to hit the api with, so bail return '' ; } if ( $ type !== 'all-rights-reserved' && empty ( $ expected [ $ type ] [ 'api' ] ) ) { // We don't know what to do with a custom license, use "all-rights-reserved" for now $ type = 'all-rights-reserved' ; } switch ( $ type ) { // api doesn't have an 'all-rights-reserved' endpoint, so manual build necessary case 'all-rights-reserved' : $ xml = '<result><html>' . "<span property='dct:title'>" . Sanitize \ sanitize_xml_attribute ( $ title ) . '</span> ' . __ ( 'Copyright' , 'pressbooks' ) . ' &#169; ' ; if ( $ year ) { $ xml .= Sanitize \ sanitize_xml_attribute ( $ year ) . ' ' . __ ( 'by' , 'pressbooks' ) . ' ' ; } $ xml .= Sanitize \ sanitize_xml_attribute ( $ copyright_holder ) ; $ xml .= '. ' . __ ( 'All Rights Reserved' , 'pressbooks' ) . '.</html></result>' ; break ; default : $ key = array_keys ( $ expected [ $ type ] [ 'api' ] ) ; $ val = array_values ( $ expected [ $ type ] [ 'api' ] ) ; $ url = $ endpoint . $ key [ 0 ] . '/' . $ val [ 0 ] . '/get?' . $ key [ 1 ] . '=' . $ val [ 1 ] . '&' . $ key [ 2 ] . '=' . $ val [ 2 ] . '&creator=' . rawurlencode ( $ copyright_holder ) . '&attribution_url=' . rawurlencode ( $ src_url ) . '&title=' . rawurlencode ( $ title ) . '&locale=' . $ lang ; if ( $ year ) { $ url .= '&year=' . ( int ) $ year ; } $ xml = wp_remote_get ( $ url ) ; $ ok = wp_remote_retrieve_response_code ( $ xml ) ; if ( absint ( $ ok ) === 200 && is_wp_error ( $ xml ) === false ) { $ xml = $ xml [ 'body' ] ; } else { // Something went wrong, try to log it if ( is_wp_error ( $ xml ) ) { $ error_message = $ xml -> get_error_message ( ) ; } elseif ( is_array ( $ xml ) && ! empty ( $ xml [ 'body' ] ) ) { $ error_message = wp_strip_all_tags ( $ xml [ 'body' ] ) ; } else { $ error_message = 'An unknown error occurred' ; } debug_error_log ( '\Pressbooks\Licensing::getLicenseXml() error: ' . $ error_message ) ; $ xml = '' ; // Set empty string } break ; } return $ xml ; }
Takes a known string from metadata, builds a url to hit an api which returns an xml response

@see https://api.creativecommons.org/docs/readme_15.html

@deprecated 5.3.0
@deprecated No longer used by internal code and no longer recommended.

@param string $type license type
@param string $copyright_holder of the page
@param string $src_url of the page
@param string $title of the page
@param string $lang (optional)
@param int $year (optional)

@return string $xml response
Takes a known string from metadata builds a url to hit an api which returns an xml response