/** * Server constructor. * * @param null $address * @param array $config * @param $mode */ public function __construct($address, $config = null, $mode = SWOOLE_PROCESS) { $info = parse_address($address); $this->sockType = $info['sock']; $this->host = $info['host']; $this->port = $info['port']; $this->mode = $mode; $this->configure($config); }
/** * Parse contributor data from a <contrib> tag, maintaining as much data as possible * @TODO better handling of contrib-type, potentially do logic on <role> within <contrib> * * @param phpQueryObj $contributor phpQuery object pertaining to a contrib tag * @return array Author data and author meta data gathered */ function parse_author($contributor) { // Basic data structure $author = array('author_id' => '', 'author_login' => '', 'author_email' => '', 'author_display_name' => '', 'author_first_name' => '', 'author_last_name' => '', 'author_url' => ''); $author_meta = array(); $contributor_type = $contributor->attr('contrib-type'); // Currently, just assume contrib-type="author" and non-existant contrib-types are authors. Note - empty contrib-types (contrib-type="") will not be processed as an author. if (strcasecmp($contributor_type, 'author') === 0 || $contributor_type === null) { // Grab supplimentary data first. So we can determine which to use over <collab> // Only direct children, we don't want to grab from <collab> $email = pq('> email', $contributor)->text(); $author_meta['affiliation'] = $affiliation = pq('> aff', $contributor)->text(); $author_meta['bio'] = pq('> bio', $contributor)->text(); $author_meta['ext-link'] = pq('> ext-link', $contributor)->attr('xlink::href'); $author_meta['uri'] = pq('> uri', $contributor)->text(); $author_meta['xref'] = pq('> xref', $contributor)->text(); // Get address information, there may be an email lurking in there $address_array = $this->parse_address(pq('> address', $contributor)); if (empty($email) && !empty($address_array['email'])) { $email = $address_array['email']; unset($address_array['email']); } // Use existing meta if its populated $author_meta = array_merge($address_array, $author_meta); // Top Level identifiers // @TODO Support contrib with <name> <collab> and <anonymous> tags...doesn't make much sense, but possible by DTD. // Handle names of individuals $name = pq('name', $contributor); $collab = pq('collab', $contributor); $anon = pq('anonymous', $contributor); if (!empty($name)) { // Always set the author ID first, so we know the key when storing user_meta $last_name = pq('surname', $name)->text(); $first_name = pq('given-names', $name)->text(); $suffix = pq('suffix', $name)->text(); $prefix = pq('prefix', $name)->text(); // Generate a (semi) unique ID for this user, hopefully this will be consistant across the XML file (other articles) $author['author_id'] = sanitize_title($last_name . $first_name . $suffix . $prefix); $author['author_display_name'] = $first_name . ' ' . $last_name; $author['author_first_name'] = $first_name; $author['author_last_name'] = $last_name; // Suffix and Prefix are user_meta. Import to check for emptiness $author_meta['prefix'] = $suffix; $author_meta['suffix'] = $prefix; } else { if (!empty($collab)) { // Use three most likely items to generate ID $contrib_group = pq('contrib-group', $collab)->text(); $affiliation = pq('> aff', $collab)->text(); $institution = pq('> institution', $collab)->text(); $author['author_id'] = sanitize_title($contrib_group . $affiliation . $institution); $author['author_display_name'] = !empty($contrib_group) ? $contrib_group : $institution; // Meta info - Bio, email etc.. gathered later $collab_meta = array(); $collab_meta['affiliation'] = $affiliation; $collab_meta['bio'] = pq('> bio', $collab)->text(); $collab_meta['ext-link'] = pq('> ext-link', $collab)->text(); $collab_meta['uri'] = pq('> uri', $collab)->text(); $collab_meta['xref'] = pq('> xref', $collab)->text(); $collab_meta['country'] = pq('country', $collab)->text(); $collab_meta['fax'] = pq('fax', $collab)->text(); $collab_meta['phone'] = pq('phone', $collab)->text(); // Meta outside of <collab> takes precendence $author_meta = array_merge($collab_meta, $author_meta); $address_array = parse_address(pq('> address', $contrib)); if (empty($email) && !empty($address_array['email'])) { $email = $address_array['email']; unset($address_array['email']); } // Use existing meta if its populated $author_meta = array_merge($address_array, $author_meta); } else { if (!empty($anon)) { $author['author_id'] = 'anonymous'; $author['author_display_name'] = 'anonymous'; } } } $author['email'] = $email; // Determine author_url, store other data in author meta. if (!empty($author_meta['uri'])) { $author['author_url'] = $author_meta['uri']; } else { if (!empty($author_meta['ext-link'])) { $author['author_url'] = $author_meta['ext-link']; } else { if (!empty($author_meta['xref'])) { $author['author_url'] = $author_meta['xref']; } } } } return array('author' => $author, 'author_meta' => $author_meta); }
$jpk_data .= "\t\t<DataDo>" . strftime('%Y-%m-%d', $dateto) . "</DataDo>\n"; $jpk_data .= "\t\t<DomyslnyKodWaluty>PLN</DomyslnyKodWaluty>\n"; $jpk_data .= "\t\t<KodUrzedu>" . (!empty($division['tax_office_code']) ? $division['tax_office_code'] : ConfigHelper::getConfig('jpk.tax_office_code', '', true)) . "</KodUrzedu>\n"; $jpk_data .= "\t</Naglowek>\n"; $jpk_data .= "\t<Podmiot1>\n"; $jpk_data .= "\t\t<IdentyfikatorPodmiotu>\n"; $jpk_data .= "\t\t\t<etd:NIP>" . preg_replace('/[\\s\\-]/', '', $division['ten']) . "</etd:NIP>\n"; $jpk_data .= "\t\t\t<etd:PelnaNazwa>" . $division['name'] . "</etd:PelnaNazwa>\n"; $jpk_data .= "\t\t\t<etd:REGON>" . $division['regon'] . "</etd:REGON>\n"; $jpk_data .= "\t\t</IdentyfikatorPodmiotu>\n"; $jpk_data .= "\t\t<AdresPodmiotu>\n"; $jpk_data .= "\t\t\t<etd:KodKraju>PL</etd:KodKraju>\n"; $jpk_data .= "\t\t\t<etd:Wojewodztwo>" . (!empty($division['state']) ? $division['state'] : ConfigHelper::getConfig('jpk.division_state', '', true)) . "</etd:Wojewodztwo>\n"; $jpk_data .= "\t\t\t<etd:Powiat>" . (!empty($division['district']) ? $division['district'] : ConfigHelper::getConfig('jpk.division_district', '', true)) . "</etd:Powiat>\n"; $jpk_data .= "\t\t\t<etd:Gmina>" . (!empty($division['borough']) ? $division['borough'] : ConfigHelper::getConfig('jpk.division_borough', '', true)) . "</etd:Gmina>\n"; $address = parse_address($division['address']); $jpk_data .= "\t\t\t<etd:Ulica>" . $address['street'] . "</etd:Ulica>\n"; $jpk_data .= "\t\t\t<etd:NrDomu>" . $address['house'] . "</etd:NrDomu>\n"; if (isset($address['flat'])) { $jpk_data .= "\t\t\t<etd:NrLokalu>" . $address['flat'] . "</etd:NrLokalu>\n"; } $jpk_data .= "\t\t\t<etd:Miejscowosc>" . $division['city'] . "</etd:Miejscowosc>\n"; $jpk_data .= "\t\t\t<etd:KodPocztowy>" . $division['zip'] . "</etd:KodPocztowy>\n"; $jpk_data .= "\t\t\t<etd:Poczta>" . ConfigHelper::getConfig('jpk.division_postal_city', $division['city']) . "</etd:Poczta>\n"; $jpk_data .= "\t\t</AdresPodmiotu>\n"; $jpk_data .= "\t</Podmiot1>\n"; $totalvalue = 0; } $invoices = array(); foreach ($ids as $idx => $invoiceid) { $invoice = $LMS->GetInvoiceContent($invoiceid);