Example #1
0
 /**
  * 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;
 }
Example #2
0
 public function parseFreeCompany($ID, $Options = null)
 {
     if (!$ID) {
         echo "error: No ID Set.";
     } else {
         // Options
         $this->defaults['automaticallyParseFreeCompanyMembers'] = isset($Options['members']) ? $Options['members'] : $this->defaults['automaticallyParseFreeCompanyMembers'];
         // Get source
         $this->getSource($this->URL['freecompany']['profile'] . $ID);
         // Create a new character object
         $FreeCompany = new FreeCompany();
         // Set Character Data
         $FreeCompany->setID(trim($ID), $this->URL['freecompany']['profile'] . $ID);
         $FreeCompany->setBasicData($this->findRange('crest_id centering_h', 10));
         $FreeCompany->setEmblum($this->findRange('ic_crest_64', 10, null, false));
         $FreeCompany->setFullDetails($this->findRange('-- Company Profile --', null, '-- //Company Profile --', false));
         // If to parse free company members
         if ($this->defaults['automaticallyParseFreeCompanyMembers']) {
             // Temp array
             $MembersList = [];
             // Get number of pages
             $TotalPages = ceil(round(intval($FreeCompany->getMemberCount()) / intval(trim($this->defaults['pagesPerFreeCompanyMemberList'])), 10));
             // Get all members
             for ($Page = 1; $Page <= $TotalPages; $Page++) {
                 // Parse Members page
                 $this->getSource($FreeCompany->getLodestone() . $this->URL['freecompany']['member'] . str_ireplace('%page%', $Page, $this->URL['freecompany']['memberpage']));
                 // Set Members
                 $MemberArray = $FreeCompany->parseMembers($this->findAll('thumb_cont_black_50', null, '/message_ic_box', false));
                 // Merge existing member list with new member array
                 $MembersList = array_merge($MembersList, $MemberArray);
             }
             // End point for member list
             $FreeCompany->setMembers($MembersList);
         }
         // Save free company
         $this->FreeCompanies[$ID] = $FreeCompany;
     }
 }