userAuthToken = $userAuthToken; $this->textAllocations = $textAllocations; } /** * Get the request and answers it. * * phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh * phpcs:disable Generic.Metrics.NestingLevel.TooHigh * phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong * * @param string $xml XML from push. * * @return string xml response */ public function handleRequest($xml) { $xmlErrorState = libxml_use_internal_errors(true); $xml = trim(stripslashes($xml)); if ($xml) { $xml = simplexml_load_string($xml); } libxml_use_internal_errors($xmlErrorState); $handler = new MiddlewareRequestHandler( $this->userAuthToken, $this->textAllocations, new XmlApiSupportedService() ); return $handler->handle($xml); } /** * Get attachment id by post id for pdf files * @param int $postId * * @return int */ public static function attachmentIdByPostParent($postId) { $attachments = get_posts([ 'post_parent' => (int)$postId, 'post_type' => 'attachment', 'post_mime_type' => 'application/pdf', 'numberposts' => 1, 'fields' => 'ids', 'suppress_filters' => true, ]); if ($attachments && isset($attachments[0])) { return (int) $attachments[0]; } return 0; } }