public function getMerchantList()
{
$merchants = array();
$merchantsMap = array();
// Get sites
$urls = array();
$urls[] = new \Oara\Curl\Request('http://publisher.publicideas.com/index.php', array());
$exportReport = $this->_client->get($urls);
$doc = new \DOMDocument();
@$doc->loadHTML($exportReport[0]);
$xpath = new \DOMXPath($doc);
$results = $xpath->query('//form[@action="reconnect.php"]/descendant::select[@name="site"]/child::option');
foreach ($results as $values) {
$siteId = $values->getAttribute("value");
$siteName = $values->textContent;
if (!isset($this->_sites[$siteId])) {
$this->_sites[$siteId] = $siteName;
$valuesLogin = array(new \Oara\Curl\Parameter('site', $siteId), new \Oara\Curl\Parameter('page', '/index.php?'));
$urls = array();
$urls[] = new \Oara\Curl\Request('http://publisher.publicideas.com/reconnect.php', $valuesLogin);
$this->_client->post($urls);
// Get the first page of programs.
$programsPerPage = 100;
$valuesPost = array(new \Oara\Curl\Parameter('nb_page', $programsPerPage), new \Oara\Curl\Parameter('action', 'myprograms'), new \Oara\Curl\Parameter('type', ''), new \Oara\Curl\Parameter('keyword', ''));
$urls = array();
$urls[] = new \Oara\Curl\Request('http://publisher.publicideas.com/index.php?action=myprograms', $valuesPost);
$exportReport = $this->_client->post($urls);
if (preg_match_all('/onclick="document.location.href=\'index.php\\?action=moreallstats&progid=(.+)\';"/', $exportReport[0], $match) && preg_match_all('/<td width="100%" class="progTitreF">(.+) «<\\/td>/', $exportReport[0], $match2)) {
for ($i = 0; $i < count($match[1]); $i++) {
$cid = $match[1][$i];
$name = $match2[1][$i];
if (!isset($merchantsMap[$cid])) {
$merchant = array();
$merchant['cid'] = $cid;
$merchant['name'] = $name;
$merchants[] = $merchant;
$merchantsMap[$cid] = true;
}
}
}
// Get nex pages of programs if they exist.
if (preg_match_all('/href="\\?action=myprograms&type=&keyword=&nb_page=' . $programsPerPage . '&index=(\\d+)&nb_page=' . $programsPerPage . '"/', $exportReport[0], $match)) {
$pages = count($match[1]) / 2;
for ($i = 1; $i <= $pages; $i++) {
$index = $programsPerPage * $i;
$urlString = 'http://publisher.publicideas.com/index.php?action=myprograms&type=&keyword=&nb_page=' . $programsPerPage . '&index=' . $index . '&nb_page=' . $programsPerPage;
$urls = array();
$urls[] = new \Oara\Curl\Request($urlString, array());
$exportReport = $this->_client->get($urls);
if (preg_match_all('/onclick="document.location.href=\'index.php\\?action=moreallstats&progid=(.+)\';"/', $exportReport[0], $match) && preg_match_all('/<td width="100%" class="progTitreF">(.+) «<\\/td>/', $exportReport[0], $match2)) {
for ($j = 0; $j < count($match[1]); $j++) {
$cid = $match[1][$j];
$name = $match2[1][$j];
if (!isset($merchantsMap[$cid])) {
$merchant = array();
$merchant['cid'] = $cid;
$merchant['name'] = $name;
$merchants[] = $merchant;
$merchantsMap[$cid] = true;
}
}
}
}
}
}
}
return $merchants;
}