This function handles the calendar-multiget REPORT.

This report is used by the client to fetch the content of a series
of urls. Effectively avoiding a lot of redundant requests.

@param CalendarMultiGetReport $report
188505
public function calendarMultiGetReport($report)
    {
        $needsJson = 'application/calendar+json' === $report->contentType;

        $timeZones = [];
        $propertyList = [];

        $paths = array_map(
            [$this->server, 'calculateUri'],
            $report->hrefs
        );

        foreach ($this->server->getPropertiesForMultiplePaths($paths, $report->properties) as $uri => $objProps) {
            if (($needsJson || $report->expand) && isset($objProps[200]['{'.self::NS_CALDAV.'}calendar-data'])) {
                $vObject = VObject\Reader::read($objProps[200]['{'.self::NS_CALDAV.'}calendar-data']);

                if ($report->expand) {
                    // We're expanding, and for that we need to figure out the
                    // calendar's timezone.
                    list($calendarPath) = Uri\split($uri);
                    if (!isset($timeZones[$calendarPath])) {
                        // Checking the calendar-timezone property.
                        $tzProp = '{'.self::NS_CALDAV.'}calendar-timezone';
                        $tzResult = $this->server->getProperties($calendarPath, [$tzProp]);
                        if (isset($tzResult[$tzProp])) {
                            // This property contains a VCALENDAR with a single
                            // VTIMEZONE.
                            $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]);
                            $timeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();
                        } else {
                            // Defaulting to UTC.
                            $timeZone = new DateTimeZone('UTC');
                        }
                        $timeZones[$calendarPath] = $timeZone;
                    }

                    $vObject = $vObject->expand($report->expand['start'], $report->expand['end'], $timeZones[$calendarPath]);
                }
                if ($needsJson) {
                    $objProps[200]['{'.self::NS_CALDAV.'}calendar-data'] = json_encode($vObject->jsonSerialize());
                } else {
                    $objProps[200]['{'.self::NS_CALDAV.'}calendar-data'] = $vObject->serialize();
                }
                // Destroy circular references so PHP will garbage collect the
                // object.
                $vObject->destroy();
            }

            $propertyList[] = $objProps;
        }

        $prefer = $this->server->getHTTPPrefer();

        $this->server->httpResponse->setStatus(207);
        $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
        $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
        $this->server->httpResponse->setBody($this->server->generateMultiStatus($propertyList, 'minimal' === $prefer['return']));
    }
466455
public static function prepareReport(Report $report)
    {
        $contents = Report::getReportFileContents($report->getFullPath());
        $report->content = $contents;
        return $report;
    }
508818
private static function getDefaultViewTypeForReport($report, $apiAction)
    {
        if (!empty($report) && $report->isEnabled()) {
            return $report->getDefaultTypeViewDataTable();
        }

        return false;
    }
628067
public function httpMkCalendar(RequestInterface $request, ResponseInterface $response)
    {
        $body = $request->getBodyAsString();
        $path = $request->getPath();

        $properties = [];

        if ($body) {
            try {
                $mkcalendar = $this->server->xml->expect(
                    '{urn:ietf:params:xml:ns:caldav}mkcalendar',
                    $body
                );
            } catch (\Sabre\Xml\ParseException $e) {
                throw new BadRequest($e->getMessage(), 0, $e);
            }
            $properties = $mkcalendar->getProperties();
        }

        // iCal abuses MKCALENDAR since iCal 10.9.2 to create server-stored
        // subscriptions. Before that it used MKCOL which was the correct way
        // to do this.
        //
        // If the body had a {DAV:}resourcetype, it means we stumbled upon this
        // request, and we simply use it instead of the pre-defined list.
        if (isset($properties['{DAV:}resourcetype'])) {
            $resourceType = $properties['{DAV:}resourcetype']->getValue();
        } else {
            $resourceType = ['{DAV:}collection', '{urn:ietf:params:xml:ns:caldav}calendar'];
        }

        $this->server->createCollection($path, new MkCol($resourceType, $properties));

        $response->setStatus(201);
        $response->setHeader('Content-Length', 0);

        // This breaks the method chain.
        return false;
    }
614392
public function writeReport(Report $report): void
    {
        $xml = new \DOMDocument('1.0', 'UTF-8');

        $root = $xml->createElement('checkstyle');
        $root->setAttribute('version', APP_NAME . '-' . APP_VERSION);

        foreach ($report->getFiles() as $file) {
            $xmlFile = $xml->createElement('file');
            $xmlFile->setAttribute('name', $file->getFilename());

            foreach ($file->getIssues() as $issue) {
                $xmlWarning = $xml->createElement('error');
                $xmlWarning->setAttribute('line', "" . $issue->getLine());
                $xmlWarning->setAttribute('severity', $issue->getSeverity());
                $xmlWarning->setAttribute('message', $issue->getMessage());
                $xmlWarning->setAttribute('source', $issue->getSource());

                if ($issue->getColumn() !== null) {
                    $xmlWarning->setAttribute('column', "" . $issue->getColumn());
                }

                $xmlFile->appendChild($xmlWarning);
            }

            $root->appendChild($xmlFile);
        }

        $xml->appendChild($root);
        $xml->formatOutput = true;

        $this->output->write($xml->saveXML());
    }
1182443
public function parseSpamReportArf()
    {
        $reports = [ ];

        //Seriously spamcop? Newlines arent in the CL specifications
        $this->arfMail['report'] = str_replace("\r", "", $this->arfMail['report']);

        preg_match_all('/([\w\-]+): (.*)[ ]*\r?\n/', $this->arfMail['report'], $regs);
        $report = array_combine($regs[1], $regs[2]);

        //Valueable information put in the body instead of the report, thnx for that Spamcop
        if (strpos($this->arfMail['message'], 'Comments from recipient') !== false) {
            preg_match(
                "/Comments from recipient.*\s]\n(.*)\n\n\nThis/s",
                str_replace(array("\r", "> "), "", $this->arfMail['message']),
                $match
            );
            $report['recipient_comment'] = str_replace("\n", " ", $match[1]);
        }

        // Add the headers from evidence into infoblob
        $parsedEvidence = new MimeParser();
        $parsedEvidence->setText($this->arfMail['evidence']);
        $headers = $parsedEvidence->getHeaders();

        foreach ($headers as $key => $value) {
            if (is_array($value) || is_object(($value))) {
                foreach ($value as $index => $subvalue) {
                    $report['headers']["${key}${index}"] = "$subvalue";
                }
            } else {
                $report['headers']["$key"] = $value;
            }
        }

        /*
         * Sometimes Spamcop has a trouble adding the correct fields. The IP is pretty
         * normal to add. In a last attempt we will try to fetch the IP from the body ourselves
         */
        if (empty($report['Source-IP'])) {
            preg_match(
                "/Email from (?<ip>[a-f0-9:\.]+) \/ " . preg_quote($report['Received-Date']) . "/s",
                $this->arfMail['message'],
                $regs
            );

            if (!empty($regs['ip']) && !filter_var($regs['ip'], FILTER_VALIDATE_IP) === false) {
                $report['Source-IP'] = $regs['ip'];
            }

            preg_match(
                "/from: (?<ip>[a-f0-9:\.]+)\r?\n?\r\n/s",
                $this->parsedMail->getMessageBody(),
                $regs
            );

            if (!empty($regs['ip']) && !filter_var($regs['ip'], FILTER_VALIDATE_IP) === false) {
                $report['Source-IP'] = $regs['ip'];
            }
        }

        $reports[] = $report;

        return $reports;
    }
91714
public function calendarQueryReport($report)
    {
        $path = $this->server->getRequestUri();

        $needsJson = 'application/calendar+json' === $report->contentType;

        $node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
        $depth = $this->server->getHTTPDepth(0);

        // The default result is an empty array
        $result = [];

        $calendarTimeZone = null;
        if ($report->expand) {
            // We're expanding, and for that we need to figure out the
            // calendar's timezone.
            $tzProp = '{'.self::NS_CALDAV.'}calendar-timezone';
            $tzResult = $this->server->getProperties($path, [$tzProp]);
            if (isset($tzResult[$tzProp])) {
                // This property contains a VCALENDAR with a single
                // VTIMEZONE.
                $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]);
                $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();

                // Destroy circular references so PHP will garbage collect the
                // object.
                $vtimezoneObj->destroy();
            } else {
                // Defaulting to UTC.
                $calendarTimeZone = new DateTimeZone('UTC');
            }
        }

        // The calendarobject was requested directly. In this case we handle
        // this locally.
        if (0 == $depth && $node instanceof ICalendarObject) {
            $requestedCalendarData = true;
            $requestedProperties = $report->properties;

            if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar-data', $requestedProperties)) {
                // We always retrieve calendar-data, as we need it for filtering.
                $requestedProperties[] = '{urn:ietf:params:xml:ns:caldav}calendar-data';

                // If calendar-data wasn't explicitly requested, we need to remove
                // it after processing.
                $requestedCalendarData = false;
            }

            $properties = $this->server->getPropertiesForPath(
                $path,
                $requestedProperties,
                0
            );

            // This array should have only 1 element, the first calendar
            // object.
            $properties = current($properties);

            // If there wasn't any calendar-data returned somehow, we ignore
            // this.
            if (isset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) {
                $validator = new CalendarQueryValidator();

                $vObject = VObject\Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
                if ($validator->validate($vObject, $report->filters)) {
                    // If the client didn't require the calendar-data property,
                    // we won't give it back.
                    if (!$requestedCalendarData) {
                        unset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
                    } else {
                        if ($report->expand) {
                            $vObject = $vObject->expand($report->expand['start'], $report->expand['end'], $calendarTimeZone);
                        }
                        if ($needsJson) {
                            $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = json_encode($vObject->jsonSerialize());
                        } elseif ($report->expand) {
                            $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = $vObject->serialize();
                        }
                    }

                    $result = [$properties];
                }
                // Destroy circular references so PHP will garbage collect the
                // object.
                $vObject->destroy();
            }
        }

        if ($node instanceof ICalendarObjectContainer && 0 === $depth) {
            if (0 === strpos((string) $this->server->httpRequest->getHeader('User-Agent'), 'MSFT-')) {
                // Microsoft clients incorrectly supplied depth as 0, when it actually
                // should have set depth to 1. We're implementing a workaround here
                // to deal with this.
                //
                // This targets at least the following clients:
                //   Windows 10
                //   Windows Phone 8, 10
                $depth = 1;
            } else {
                throw new BadRequest('A calendar-query REPORT on a calendar with a Depth: 0 is undefined. Set Depth to 1');
            }
        }

        // If we're dealing with a calendar, the calendar itself is responsible
        // for the calendar-query.
        if ($node instanceof ICalendarObjectContainer && 1 == $depth) {
            $nodePaths = $node->calendarQuery($report->filters);

            foreach ($nodePaths as $path) {
                list($properties) =
                    $this->server->getPropertiesForPath($this->server->getRequestUri().'/'.$path, $report->properties);

                if (($needsJson || $report->expand)) {
                    $vObject = VObject\Reader::read($properties[200]['{'.self::NS_CALDAV.'}calendar-data']);

                    if ($report->expand) {
                        $vObject = $vObject->expand($report->expand['start'], $report->expand['end'], $calendarTimeZone);
                    }

                    if ($needsJson) {
                        $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = json_encode($vObject->jsonSerialize());
                    } else {
                        $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = $vObject->serialize();
                    }

                    // Destroy circular references so PHP will garbage collect the
                    // object.
                    $vObject->destroy();
                }
                $result[] = $properties;
            }
        }

        $prefer = $this->server->getHTTPPrefer();

        $this->server->httpResponse->setStatus(207);
        $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
        $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
        $this->server->httpResponse->setBody($this->server->generateMultiStatus($result, 'minimal' === $prefer['return']));
    }
210780
protected function processReportParameters (Report $report)
    {
        // NOTE: Remove parameters which have NULL values, etc
        $globalParameters = $this->resetEmptyParameters();
        $reportParameters = $report->resetEmptyParameters();

        // NOTE: Report parameters will over-write the global Starter parameters
        $mergedParameters = array_merge($globalParameters, $reportParameters);

        $parameters = '';
        if (!empty($mergedParameters)) {
            $parameters = '-P ';
            foreach ($mergedParameters as $name => $value) {
                $value = is_numeric($value) ? $value : "'$value'";
                $parameters .= "$name=$value ";
            }
        }

        return $parameters;
    }
327161
public function run(JobReport $report)
    {
        $this->report = $report;
        $report->setStartTime(microtime(true));
        $this->getProcess()->start(function ($type, $buffer) use ($report) {
            if (Process::ERR === $type) {
                $report->addError($buffer);
            } else {
                $report->addOutput($buffer);
            }
        });
    }
137455
public String makeReport(String name, String report) {
        long increment = Long.valueOf(report);
        long currentLineCount = globalLineCounter.addAndGet(increment);

        if (currentLineCount >= maxScenarios) {
            return "exit";
        } else {
            return "ok";
        }
    }
891425
public function setReport(\Gpupo\CommonSchema\ORM\Entity\Banking\Report\Report $report = null)
    {
        $this->report = $report;

        return $this;
    }
990855
public function addReport($report)
    {
        $report = (array) $report;

        foreach ($report as $r) {
            if (!preg_match('/^{([^}]*)}(.*)$/', $r)) {
                throw new DAV\Exception('Reportname must be in clark-notation');
            }
            $this->reports[] = $r;
        }
    }
1113977
public function report($reportName, $report, $path)
    {
        switch ($reportName) {
            case '{DAV:}principal-property-search':
                $this->server->transactionType = 'report-principal-property-search';
                $this->principalPropertySearchReport($path, $report);

                return false;
            case '{DAV:}principal-search-property-set':
                $this->server->transactionType = 'report-principal-search-property-set';
                $this->principalSearchPropertySetReport($path, $report);

                return false;
            case '{DAV:}expand-property':
                $this->server->transactionType = 'report-expand-property';
                $this->expandPropertyReport($path, $report);

                return false;
            case '{DAV:}principal-match':
                $this->server->transactionType = 'report-principal-match';
                $this->principalMatchReport($path, $report);

                return false;
            case '{DAV:}acl-principal-prop-set':
                $this->server->transactionType = 'acl-principal-prop-set';
                $this->aclPrincipalPropSetReport($path, $report);

                return false;
        }
    }
1276243
public function getReportView($reportUri, $format = 'html') {
        if ($this->isConnected()) {
            //Create an event with default params and pass it to the event listener to process
            $reportViewerEvent = new ReportViewerRequestEvent($format, 1);
            $this->eventDispatcher->dispatch('Mesd.jasperreport.report_viewer_request', $reportViewerEvent);
            if ($reportViewerEvent->isPropagationStopped()) {
                if ($reportViewerEvent->isAsset()) {
                    return $this->getReportAsset($reportViewerEvent->getAssetUri(), $reportViewerEvent->getJSessionId());
                } else {
                    $params = '&page=' . $reportViewerEvent->getReportPage();
                    $format = $reportViewerEvent->getReportFormat();
                }
            } else {
                $params = '&page=1';
            }

            //Create new report object
            $report = new Report($reportUri, $format);

            //Create the builder
            $reportBuilder = new ReportBuilder(
                $this->jasperClient
                , $report
                , $params
                , $this->router->getMatcher()->getContext()->getBaseUrl() . $this->router->getMatcher()->getContext()->getPathInfo() . '?asset=true'
                , 'Fallback'
           );

            return $reportBuilder;
        } else {
            return false;
        }
    }
1346901
public function _processContactImportReportFaults($id, $websiteId)
    {
        $client = $this->helper->getWebsiteApiClient($websiteId);
        $report = $client->getContactImportReportFaults($id);

        if ($report) {
            $reportData = explode(PHP_EOL, $this->_removeUtf8Bom($report));
            //unset header
            unset($reportData[0]);
            //no data in report
            if (! empty($reportData)) {
                $contacts = [];
                foreach ($reportData as $row) {
                    $row = explode(',', $row);
                    //reason
                    if (in_array($row[0], $this->reasons)) {
                        //email
                        $contacts[] = $row[1];
                    }
                }

                //unsubscribe from email contact and newsletter subscriber tables
                $this->helper->contactResource->unsubscribe($contacts);
            }
        }
    }
505834
protected function freeBusyQueryReport(Xml\Request\FreeBusyQueryReport $report)
    {
        $uri = $this->server->getRequestUri();

        $acl = $this->server->getPlugin('acl');
        if ($acl) {
            $acl->checkPrivileges($uri, '{'.self::NS_CALDAV.'}read-free-busy');
        }

        $calendar = $this->server->tree->getNodeForPath($uri);
        if (!$calendar instanceof ICalendar) {
            throw new DAV\Exception\NotImplemented('The free-busy-query REPORT is only implemented on calendars');
        }

        $tzProp = '{'.self::NS_CALDAV.'}calendar-timezone';

        // Figuring out the default timezone for the calendar, for floating
        // times.
        $calendarProps = $this->server->getProperties($uri, [$tzProp]);

        if (isset($calendarProps[$tzProp])) {
            $vtimezoneObj = VObject\Reader::read($calendarProps[$tzProp]);
            $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();
            // Destroy circular references so PHP will garbage collect the object.
            $vtimezoneObj->destroy();
        } else {
            $calendarTimeZone = new DateTimeZone('UTC');
        }

        // Doing a calendar-query first, to make sure we get the most
        // performance.
        $urls = $calendar->calendarQuery([
            'name' => 'VCALENDAR',
            'comp-filters' => [
                [
                    'name' => 'VEVENT',
                    'comp-filters' => [],
                    'prop-filters' => [],
                    'is-not-defined' => false,
                    'time-range' => [
                        'start' => $report->start,
                        'end' => $report->end,
                    ],
                ],
            ],
            'prop-filters' => [],
            'is-not-defined' => false,
            'time-range' => null,
        ]);

        $objects = array_map(function ($url) use ($calendar) {
            $obj = $calendar->getChild($url)->get();

            return $obj;
        }, $urls);

        $generator = new VObject\FreeBusyGenerator();
        $generator->setObjects($objects);
        $generator->setTimeRange($report->start, $report->end);
        $generator->setTimeZone($calendarTimeZone);
        $result = $generator->getResult();
        $result = $result->serialize();

        $this->server->httpResponse->setStatus(200);
        $this->server->httpResponse->setHeader('Content-Type', 'text/calendar');
        $this->server->httpResponse->setHeader('Content-Length', strlen($result));
        $this->server->httpResponse->setBody($result);
    }
364918
static function parseReport(string $report): Job {
    $records = Report::fromCoverage($report)->getRecords()->getArrayCopy();
    $workingDir = getcwd() ?: '.';

    return new Job(array_map(function(Record $record) use ($workingDir) {
      $sourceFile = $record->getSourceFile();
      $source = (string)@file_get_contents($sourceFile);
      if (!mb_strlen($source)) {
        throw new \RuntimeException("Source file not found: $sourceFile");
      }

      $coverage = new \SplFixedArray(count(preg_split('/\r?\n/', $source) ?: []));
      if ($lines = $record->getLines()) {
        foreach ($lines->getData() as $lineData) {
          $coverage[$lineData->getLineNumber() - 1] = $lineData->getExecutionCount();
        }
      }

      $filename = Path::makeRelative($sourceFile, $workingDir);
      return new SourceFile($filename, md5($source), $source, $coverage->toArray());
    }, $records));
  }