/** * Get freecompany * * @param $freeCompanyId - the id of the freecompany * @param $members - with memberlist */ private function advancedFreecompanyParse($freeCompanyId, $members = false) { // Generate url $url = $this->urlGen('freecompany', ['{id}' => $freeCompanyId]); $rawHtml = $this->trim($this->curl($url), '<!-- #main -->', '<!-- //#main -->'); $html = html_entity_decode(preg_replace(array('#\\s\\s+#s', '#[\\n\\t]#s', '#<!--\\s*-->#s'), '', $rawHtml), ENT_QUOTES); $freeCompany = new FreeCompany(); $headerHtml = $this->trim($html, '<!-- playname -->', '<!-- //playname -->'); $freeCompany->id = $freeCompanyId; $headerRegExp = '#' . $this->getRegExp('image', 'fcIcon1') . '.*?' . $this->getRegExp('image', 'fcIcon2') . '.*?' . '(?:' . $this->getRegExp('image', 'fcIcon3') . '.*?)?' . '.*?crest_id.*?>(?<company>.*?)\\s?<.*?<span>\\s?\\((?<world>.+?)\\)</span>#'; $headerMatches = array(); if (preg_match($headerRegExp, $headerHtml, $headerMatches)) { $freeCompany->emblum = array($headerMatches['fcIcon1'], $headerMatches['fcIcon2'], $headerMatches['fcIcon3']); $freeCompany->company = $headerMatches['company']; $freeCompany->server = $headerMatches['world']; } $baseHtml = $this->trim($html, '<!-- Company Profile -->', '<!-- //Company Profile -->'); $regExp = '#<td class="vm"><span class="txt_yellow">(?<name>.*?)</span><br>«(?<tag>.*?)»</td>.*?' . 'ldst_strftime\\((?<formed>[\\d\\.]+),.*?' . '<td>(?<activeMember>[\\d]+)</td>.*?' . '<td>(?<rank>[\\d]+)</td>.*?' . '</th><td>.*?:\\s*(?<weeklyRank>[\\d\\-]+)\\s*.*?<br>.*?:\\s*(?<monthlyRank>[\\d\\-]+).*?</td>.*?' . '</th><td>(?<slogan>.*?)</td>.*?' . '<tr>.*?</tr><tr>.*?</tr>.*?' . '<td>(?!<ul>)(?<active>.*?)</td>.*?' . '<td>(?<recruitment>.*?)</td>.*?' . '<td>' . '(?(?=<div)' . '<div class="txt_yellow.*?">(?<estateZone>.*?)</div>.*?' . '<p class="mb10.*?">(?<estateAddress>.*?)</p>.*?' . '<p class="mb10.*?">(?<estateGreeting>.*?)</p>' . ').*?</td>.*?' . '#'; $matches = array(); if (preg_match($regExp, $baseHtml, $matches)) { $freeCompany->name = $matches['name']; $freeCompany->tag = $matches['tag']; $freeCompany->formed = $matches['formed']; $freeCompany->id = $freeCompanyId; $freeCompany->memberCount = $matches['activeMember']; $freeCompany->slogan = $matches['slogan']; $freeCompany->active = $matches['active']; $freeCompany->recruitment = $matches['recruitment']; $freeCompany->ranking = array('current' => $matches['rank'], 'weekly' => $matches['weeklyRank'], 'monthly' => $matches['monthlyRank']); if (array_key_exists('estateZone', $matches)) { $freeCompany->estate = array('zone' => $matches['estateZone'], 'address' => $matches['estateAddress'], 'message' => $matches['estateGreeting']); } } // Focus & Seeking $regExp = '#<li(?: class="icon_(?<active>off?)")?><img src="(?<icon>.*?/ic/(?<type>focus|roles)/.*?)\\?.*?title="(?<name>.*?)">#'; $FocusOrSeekingMatches = array(); preg_match_all($regExp, $baseHtml, $FocusOrSeekingMatches, PREG_SET_ORDER); foreach ($FocusOrSeekingMatches as $key => $match) { $freeCompany->{$match['type']}[] = ['name' => $match['name'], 'icon' => $match['icon'], 'active' => $match['active'] != "" ? false : true]; } if ($members === true) { $freeCompany->members = array(); $url = $this->urlGen('freecompanyMember', ['{id}' => $freeCompany->id]); $rawHtml = $this->trim($this->curl($url), '<!-- Member List -->', '<!-- //Member List -->'); $html = html_entity_decode(preg_replace(array('#\\s\\s+#s', '#[\\n\\t]#s', '#<script.*?>.*?</script>?#s', '#<!--\\s*-->#s'), '', $rawHtml), ENT_QUOTES); $maxPerPage = strip_tags($this->trim($html, '<span class="show_end">', '</span>')); $pages = ceil($freeCompany->memberCount / $maxPerPage); $memberHtml = ""; for ($page = 1; $page <= $pages; $page++) { if ($page == 1) { $memberHtml .= $this->trim($html, 'table_black_border_bottom', '<!-- pager -->'); } else { $pageUrl = $this->urlGen('freecompanyMemberPage', ['{id}' => $freeCompanyId, '{page}' => $page]); $rawPageHtml = $this->trim($this->curl($pageUrl), '<!-- Member List -->', '<!-- //Member List -->'); $pageHtml = html_entity_decode(preg_replace(array('#\\s\\s+#s', '#[\\n\\t]#s', '#<script.*?>.*?</script>?#s', '#<!--\\s*-->#s'), '', $rawPageHtml), ENT_QUOTES); $memberHtml .= $this->trim($pageHtml, 'table_black_border_bottom', '<!-- pager -->'); } } $freeCompany->members = $this->_advancedFcMemberParse($memberHtml); } // dust up $freeCompany->clean(); return $freeCompany; }