Advertisement
Guest User

Untitled

a guest
Feb 1st, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.59 KB | None | 0 0
  1. <?php
  2. /**
  3.  * ZANOX
  4.  * -----------------------------------------------------------------------------
  5.  */
  6. class AffiliStat_Zanox extends AffiliStat implements iAffiliStat
  7. {
  8.     public function __construct()
  9.     {
  10.         parent::__construct();
  11.     }
  12.  
  13.     public function __destruct()
  14.     {
  15.         parent::__destruct();
  16.     }
  17.  
  18.     /**
  19.      * Connexion
  20.      */
  21.     public function login()
  22.     {
  23.         $URL = 'https://ui.zanox.com/bin/z_in_frm.dll?1001100110030&0c0&201_981202310868_113_201';
  24.  
  25.         $data = array(
  26.                     't_login_user_name' => $this->login,
  27.                     't_login_password' => $this->passe,
  28.                     'fx_loginform' => '',
  29.                     'b_next' => 'Ouvrir+une+session',
  30.                 );
  31.  
  32.         curl_setopt($this->ch, CURLOPT_URL, $URL);
  33.         curl_setopt($this->ch, CURLOPT_HEADER, true);
  34.         curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->implode_array($data));
  35.         curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
  36.         curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->_getCookie());
  37.         //curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->_getCookie());
  38.         $String = curl_exec($this->ch);
  39. // echo $String;
  40.  
  41.         $mes_static = preg_replace('|.*statistic.html\?([^"]*)" class="head_nav_main_normal">.*|is','$1',$String);
  42.         $mes_static = str_replace('&amp;','&',$mes_static);
  43. // echo $mes_static;
  44.        
  45.  
  46.         /**
  47.          * Mes statistiques
  48.          */
  49.         $URL = 'https://publisher.zanox.com/publisher_stats_classic/statistic.html?' . $mes_static;
  50. //echo $URL;
  51.         curl_setopt($this->ch, CURLOPT_URL, $URL);
  52.         curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
  53.         $String = curl_exec($this->ch);
  54. //echo $String;
  55.  
  56.         //preg_match('|.*<a href="([^"]*)">Lien sur les statistiques.*|is', $String, $rawmes_static);
  57.         //$mes_static = $rawmes_static[1];
  58.  
  59.         preg_match('/<li class="releaseHistoryLinkItem"><a href="([^"]*)/', $String, $rawurl);
  60.         $mes_static = $rawurl[1];
  61. //print_r($rawurl);        
  62. //        $mes_static = str_replace('&amp;','&',$mes_static);
  63. //echo $mes_static;        
  64.  
  65.         /**
  66.          * Mes statistiques
  67.          */
  68.         $URL = $mes_static;
  69. //echo $URL;
  70.         //$ch = curl_init();
  71.         curl_setopt($this->ch, CURLOPT_URL, $URL);
  72.         curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
  73.         //curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_getCookie());
  74.         //curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_getCookie());
  75.         $String = curl_exec($this->ch);
  76. //echo $String;
  77.  
  78.         preg_match('/<a class="prmreiter_nonactiv" style="border:0px;" href="([^"]*)/', $String, $rawurl2);
  79.         $stat_det = $rawurl2[1];
  80. //echo $stat_det;      
  81. //        $stat_det = preg_replace('|.*style="border:0px;" href="([^"]*)">Statistiques détaillées.*|is','$1',$String);
  82. //        $stat_det = str_replace('&amp;','&',$stat_det);
  83.  
  84.         /**
  85.          * On récupère le lien "action" des stats en temps réél
  86.          */
  87.         preg_match('/<form method="post" action="([^"]*)/', $String, $rawurl3);
  88.         $stat_reel = $rawurl3[1];
  89. //echo $stat_reel;       
  90.         //$stat_reel = preg_replace('|.*<form method="post" action="([^"]*)" id="fx_form" name="tstest">.*|is','$1',$String);
  91.         //$stat_reel = str_replace('&amp;','&',$stat_reel);
  92.         $this->stat_reel = $stat_reel;
  93.  
  94.         /**
  95.          * Stat détaillé
  96.          */
  97.         $URL = $stat_det;
  98. //echo $URL;
  99.         //$ch = curl_init();
  100.         curl_setopt($this->ch, CURLOPT_URL, $URL);
  101.         /*
  102.         curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
  103.         curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_getCookie());
  104.         curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_getCookie());
  105.         */
  106.         $String = curl_exec($this->ch);
  107. //echo $String;        
  108.         //curl_close($ch);
  109.  
  110.         $stat_custom = preg_replace('|.*<form method="post" action="([^"]*)" id="fx_form" name="tstest">.*|is','$1',$String);
  111.         $this->stat_custom = str_replace('&amp;','&',$stat_custom);
  112.        
  113.         //echo $this->stat_custom.'<br /><br />';
  114.  
  115.         // on enregistre quelques données de sessions Zanox
  116.         $arrRecord = array($this->_getRecordValue() =>
  117.                         array(
  118.                             'mes_static' => $mes_static,
  119.                             'time' => time(),
  120.                             'stat_custom' => $this->stat_custom,
  121.                             'stat_reel' => $this->stat_reel
  122.                         )
  123.                     );
  124.         $this->_setRecord($arrRecord);
  125.     }
  126.  
  127.     /**
  128.      * Stats par jour
  129.      */
  130.     public function parJour($parDate=NULL, $moinsJour=NULL)
  131.     {
  132.         if ($moinsJour == 0 && !isset($this->param['channel']) )
  133.         {
  134.             $data = array(
  135.                         'd_accounting_currency' => '1',
  136.                         'r_light_report_select' => '1',
  137.                         'b_next' => 'Afficher+les+Stats'
  138.                     );
  139.             $URL = $this->stat_reel;
  140.            
  141.             //$ch = curl_init();
  142.             curl_setopt($this->ch, CURLOPT_URL, $URL);
  143.             //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  144.             curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->implode_array($data));
  145.             //curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_getCookie());
  146.             //curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_getCookie());
  147.             $String = curl_exec($this->ch);
  148.  
  149.             //curl_close($ch);
  150.  
  151.             $total = preg_replace('|.*Total.*right(.*)&nbsp;</div>.*<!-- result navi -->.*|is','$1',$String);
  152.             $total = str_replace(',','.',ereg_replace("[^0-9,]","",$total));
  153.  
  154.             $return = array();
  155.             $return[$parDate] = $total;
  156.             return $return;
  157.         }
  158.         else
  159.         {
  160.             if ($moinsJour !== NULL)
  161.             {
  162.                 $parDate = date('d/m/Y',time()-3600*24*$moinsJour);
  163.             }
  164.  
  165.             $dateZanox = str_replace('/','.',$parDate);
  166.             //echo $dateZanox;        
  167.  
  168.  
  169.             $data = $this->_parametreDay($dateZanox);
  170.  
  171.             $URL = $this->stat_custom;
  172.  
  173.             //$ch = curl_init();
  174.             curl_setopt($this->ch, CURLOPT_URL, $URL);
  175.             //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  176.             curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->implode_array($data));
  177.             //curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_getCookie());
  178.             //curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_getCookie());
  179.             $String = curl_exec($this->ch);
  180.  
  181.             //echo '<br /><br />STRING--<br />'.$String.'<br /><br />';
  182.  
  183.             //curl_close($ch);
  184.  
  185.             $total = preg_replace('|.*Total.*right(.*)&nbsp;</div>.*<!-- result navi -->.*|is','$1',$String);
  186.             $total = str_replace(',','.',ereg_replace("[^0-9,]","",$total));
  187.  
  188.             $return = array();
  189.             $return[$parDate] = $total;
  190.  
  191.             return $return;
  192.         }
  193.     }
  194.  
  195.     /**
  196.      * Stats par mois
  197.      */
  198.     public function parMois($mois=NULL, $an=NULL, $moinsMois=NULL)
  199.     {
  200.         if ($moinsMois !== NULL)
  201.         {
  202.             $leMois = date('m/Y',strtotime('-' . $moinsMois . ' month'));
  203.             $data = $this->_parametreMois(
  204.                         date('Y',strtotime('-' . $moinsMois . ' month')),
  205.                         date('m',strtotime('-' . $moinsMois . ' month')));
  206.         }
  207.         elseif ($mois !== NULL && $an !== NULL)
  208.         {
  209.             $leMois = $mois.'/'.$an;
  210.             $data = $this->_parametreMois(
  211.                         $an,
  212.                         $mois);
  213.         }
  214.  
  215.         $URL = $this->stat_custom;
  216.  
  217.         //$ch = curl_init();
  218.         curl_setopt($this->ch, CURLOPT_URL, $URL);
  219.         //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  220.         curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->implode_array($data));
  221.         //curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_getCookie());
  222.         //curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_getCookie());
  223.         $String = curl_exec($this->ch);
  224.         //curl_close($ch);
  225.  
  226.  
  227.         $total = preg_replace('|.*Total.*right(.*)&nbsp;</div>.*<!-- result navi -->.*|is','$1',$String);
  228.         $total = str_replace(',','.',ereg_replace("[^0-9,]","",$total));
  229.  
  230.         $return = array();
  231.         $return[$leMois] = $total;
  232.  
  233.         return $return;
  234.     }
  235.  
  236.     /**
  237.      * On est connecté ?
  238.     public function isConnecte()
  239.     {
  240.         $arrRecordFile = $this->_getRecord();
  241.         $arrRecordFile = $arrRecordFile[$this->_getRecordValue()];
  242.  
  243.         if (isset($arrRecordFile))
  244.         {
  245.             $diffTime = time()-(int)$arrRecordFile['time'];
  246.            
  247.             if ($arrRecordFile['mes_static'] == 'wait')
  248.             {
  249.                 sleep(6);
  250.                 $arrRecordFile = $this->_getRecord();
  251.                 $arrRecordFile = $arrRecordFile[$this->_getRecordValue()];
  252.             }
  253.  
  254.            
  255.             if ($diffTime < (15*60))
  256.             {
  257.                 $ch = curl_init();
  258.                 curl_setopt($ch, CURLOPT_URL, $arrRecordFile['mes_static']);
  259.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  260.                 curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_getCookie());
  261.                 curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_getCookie());
  262.                 $String = curl_exec($ch);
  263.                 curl_close($ch);
  264.  
  265.                 if (!preg_match('|.*Erreur.*|is',$String) && !preg_match('|.*Error.*|is',$String))
  266.                 {
  267.                     $this->stat_custom = $arrRecordFile['stat_custom'];
  268.                     $this->stat_reel = $arrRecordFile['stat_reel'];
  269.                     return true;
  270.                 }
  271.             }
  272.         }
  273.        
  274.         // on enregistre quelques données de sessions Zanox
  275.         $arrRecord = array($this->_getRecordValue() =>
  276.                         array(
  277.                             'mes_static' => 'wait'
  278.                         )
  279.                     );
  280.         $this->_setRecord($arrRecord);
  281.  
  282.         return false;
  283.     }
  284.      */
  285.  
  286.  
  287.     /**
  288.      * Fonction
  289.      */
  290.     private function _parametreDay ($date)
  291.     {
  292.         return array(
  293.             'b_next' => 'any',
  294.             't_date' => $date,
  295.             'd_website_name' => '0',
  296.             'd_adbox_name' => '0',
  297.             'd_prog_name' => '0',
  298.             'd_link_name' => '0',
  299.             'd_accounting_currency' => '1',
  300.             'c_show_view' => 'c_show_view',
  301.             'c_show_click' => 'c_show_click',
  302.             'c_show_lead' => 'c_show_lead',
  303.             'c_show_sale' => 'c_show_sale',
  304.             'd_screen_file' => '0',
  305.             'd_group' => '1',
  306.         );
  307.     }
  308.  
  309.     private function _parametreMois ($dateAn, $dateMois)
  310.     {
  311.         $data = array(
  312.             'b_next' => 'any',
  313.             'd_periode_year' => $dateAn,
  314.             'd_periode_month' => $dateMois,
  315.             'd_periode_week' => '0',
  316.             't_date' => '',
  317.             'd_adbox_name' => '0',
  318.             'd_prog_name' => '0',
  319.             'd_link_name' => '0',
  320.             'd_accounting_currency' => '1',
  321.             'c_show_view' => 'c_show_view',
  322.             'c_show_click' => 'c_show_click',
  323.             'c_show_lead' => 'c_show_lead',
  324.             'c_show_sale' => 'c_show_sale',
  325.             'd_screen_file' => '0',
  326.             'd_group' => '1',
  327.         );
  328.  
  329.         if (isset($this->param['channel']) && !empty($this->param['channel']))
  330.         {
  331.             $data += array('d_website_name' => $this->param['channel']);
  332.         }
  333.         else
  334.         {
  335.             $data += array('d_website_name' => '0');
  336.         }
  337.  
  338.         return $data;
  339.     }
  340. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement