Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * NET AFFILIATION
- $regie->setRegie('NetAffiliation', // nom de la régie indiqué ci-dessus
- array(
- 'login' => '', //email de login
- 'passe' => '', //mdp du web service sur la plateforme
- 'channel' => '' //id du site à renseigner obligatoirement
- )
- );
- * -----------------------------------------------------------------------------
- */
- class AffiliStat_NetAffiliation extends AffiliStat implements iAffiliStat
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function __destruct()
- {
- parent::__destruct();
- }
- /**
- * Connexion
- */
- public function login()
- {
- /* On recup charge.php pour pouvoir se connecter */
- $URL = 'https://stat.netaffiliation.com/listing.php?authl='.$this->login.'&authv='.$this->passe.'&debut=2013-11-01&fin=2013-11-14&champs=idcamp,nomcamp,idsite,nomsite,gaiatt,gaival';
- //echo $URL;
- $data = array(
- 'identif' => $this->login,
- 'mdp' => $this->passe
- );
- }
- /**
- * Stats par jour
- */
- public function parJour($parDate=NULL, $moinsJour=NULL)
- {
- if ($moinsJour !== NULL)
- {
- $parDate = date('Y-m-d',time()-3600*24*$moinsJour);
- }
- //$URL = 'https://stat.netaffiliation.com/listing.php?authl='.$this->login.'&authv='.$this->passe.'&debut='.$parDate.'&fin='.$parDate.'&champs=gaiatt,gaival';
- $URL = 'https://stat.netaffiliation.com/listing.php?authl='.$this->login.'&authv='.$this->passe.'&debut='.$parDate.'&fin='.$parDate.'&champs=idsite,gaiatt,gaival&dim=2';
- //echo $URL;
- $xml = file_get_contents($URL);
- $rows = explode(PHP_EOL, $xml);
- $total = array();
- foreach($rows as $row){
- $row1 = explode(';', $row);
- //print_r($row1);
- $channel = $this->param['channel'];
- if(($row1[1] != '') AND ($row1[0] == $channel)){
- $rowtotal = $row1[1] + $row1[2];
- $total[] = $rowtotal;
- }
- }
- $return[$parDate] = array_sum($total);
- return $return;
- }
- /**
- * Stats par mois
- */
- public function parMois($mois=NULL, $an=NULL, $moinsMois=NULL)
- {
- if ($moinsMois !== NULL)
- {
- $leMois = date('Y-m',strtotime('-' . $moinsMois . ' month'));
- $data = $this->_parametre(
- date('Y-m-01',strtotime('-' . $moinsMois . ' month')),
- date('Y-m-t',strtotime('-' . $moinsMois . ' month')));
- //print_r($data);
- $debutmois = $data['dateDailyDeb1'];
- $finmois = $data['dateDailyFin1'];
- }
- elseif ($mois !== NULL && $an !== NULL)
- {
- $leMois = $mois.'-'.$an;
- $data = $this->_parametre(
- date('Y-m-01',strtotime('-' . $moinsMois . ' month')),
- date('Y-m-t',strtotime('-' . $moinsMois . ' month')));
- //print_r($data);
- $debutmois = $data['dateDailyDeb1'];
- $finmois = $data['dateDailyFin1'];
- }
- $URL = 'https://stat.netaffiliation.com/listing.php?authl='.$this->login.'&authv='.$this->passe.'&debut='.$debutmois.'&fin='.$finmois.'&champs=idsite,gaiatt,gaival&dim=2';
- //echo $URL;
- $xml = file_get_contents($URL);
- $rows = explode(PHP_EOL, $xml);
- $total = array();
- foreach($rows as $row){
- $row1 = explode(';', $row);
- //print_r($row1);
- $channel = $this->param['channel'];
- if(($row1[1] != '') AND ($row1[0] == $channel)){
- $rowtotal = $row1[1] + $row1[2];
- $total[] = $rowtotal;
- }
- }
- $return[$parDate] = array_sum($total);
- return $return;
- }
- /**
- * On est connecté ?
- */
- public function isConnecte()
- {
- $arrRecordFile = $this->_getRecord();
- $arrRecordFile = $arrRecordFile[$this->_getRecordValue()];
- if (isset($arrRecordFile))
- {
- $diffTime = time()-(int)$arrRecordFile['time'];
- if ($diffTime < (15*60))
- {
- $URL = 'http://'.$arrRecordFile['sousDomaine'].'.netaffiliation.com/aff/';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $URL);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_getCookie());
- curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_getCookie());
- $String = curl_exec($ch);
- curl_close($ch);
- if (!preg_match('|.*302 Found.*|is',$String))
- {
- $this->sousDomaine = $arrRecordFile['sousDomaine'];
- return true;
- }
- }
- }
- return false;
- }
- /**
- * Fonction
- */
- private function _parametre ($dateDeb, $dateFin)
- {
- return array(
- 'dateDailyDeb1' => $dateDeb,
- 'dateDailyFin1' => $dateFin,
- 'mode' => 'AjaxDaily',
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement