Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/topic.php on line 737
Форумы портала PHP.SU :: помогите оптимизировать код

 PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи


 Страниц (1): [1]   

> Без описания
tgcoin
Отправлено: 12 Февраля, 2012 - 10:06:51
Post Id


Гость


Покинул форум
Сообщений всего: 86
Дата рег-ции: Дек. 2011  


Помог: 0 раз(а)




CODE (htmlphp):
скопировать код в буфер обмена
  1.  
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  3. "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <title>Мониторинг обменных пунктов электронных валют</title>
  7.   <meta name="description" content="Курсы надежных обменных пунктов, меняющих WMR на WMZ (WebMoney на WebMoney). Список выгодных обменников, работающих с обменом WMR на WMZ.">
  8.   <meta name="keywords" content="WMR, обменники, WMZ, курсы, WebMoney, список обменников, мониторинг, лучшие курсы, обмен валют, обменные пункты">
  9.   <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
  10.   <meta http-equiv="Pragma" content="no-cache">
  11.   <meta http-equiv="Cache-Control" content="no-cache">
  12. <link type="text/css" rel="stylesheet" href="main.css">
  13. </head>
  14. <body>
  15. <table cellpadding="0" cellspacing="0" border="0" class="content">
  16. <tr>
  17.  
  18. <td><h2>&nbsp;&nbsp;Мониторинг курсов обменных пунктов</h2></td>
  19. </tr>
  20. <tr>
  21.         <td class="contentLeft">
  22.         <!--content-->
  23. <script language="JavaScript" type="text/javascript">
  24.    var select1 = 0;
  25.    var select2 = 0;
  26.    var temp1 = 0;
  27.    var temp2 = 0;
  28.  
  29.    function goto_list() {
  30.      document.location='index.php?c1='+document.select_currency.from.value+'&c2='+document.select_currency.to.value;
  31.    }
  32.  
  33.    function auto_direct(select1, select2) {
  34.      if (select1 == 1) {
  35.        temp1 = select1;
  36.      }
  37.      if (select2 == 1) {
  38.        temp2 = select2;
  39.      }
  40.      if ((temp1 == 1)&&(temp2 == 1)) {
  41.        goto_list();
  42.      }
  43.    }
  44.  
  45.    nr = false;
  46.    function f_cl(url) {
  47.      if (nr) {
  48.        nr = false;
  49.        return false;
  50.      }
  51.      window.open('go.php?'+url);
  52.    }
  53.  
  54.    
  55.  </script>  
  56. <?php
  57.  
  58. include ('db.php');
  59.  
  60. function itfalse($x)
  61.          {
  62.              global $se;        $ok=0;
  63.             for ($j = 3; $j < 15; $j++)
  64.               {
  65.                   if ($se[$x][$j] == 40)   { $ok++; }
  66.               }     return $ok;
  67.  
  68.          }
  69.          function iscount2($x,$y)
  70.          {
  71.           if (($x == 7) and ($y == 7)) { return 0; }
  72.           if (($x == 1) and ($y == 0)) { return 1; }
  73.           if (($x == 3) )  { return 2; }
  74.           if (($x == 2) and ($y == 6)) { return 3; }
  75.           if (($x == 2) and ($y == 1))  { return 4; }
  76.           if (($x == 6) and ($y == 5))  { return 5; }
  77.           if (($x == 7) and ($y == 4))  { return 6; }
  78.           if (($x == 1) and ($y == 2))  { return 7; }
  79.           if (($x == 6) and ($y == 6))  { return 8; }
  80.  
  81.           if (($x == 4))  { return 9; }
  82.          }
  83.                    function iscount($x,$y)  //1 2 digit
  84.          {
  85.           if ( ($x == 1) and ($y == 0) )  { return 1; }
  86.           if (($x == 5) and ($y == 4)) { return 2; }
  87.           if (($x == 2) and ($y == 7)) { return 3; }
  88.           if (($x == 2) and ($y == 10))  { return 4; }
  89.           if (($x == 7) and ($y == 5)) { return 5; }
  90.           if (($x == 8) and ($y == 5))  { return 6; }
  91.              if (($x == 1) and ($y == 3))  { return 7; }
  92.           if (($x == 7) and ($y == 7))  { return 8; }
  93.           if (($x == 5) and ($y == 8))  { return 9; }
  94.            if (($x == 8) and ($y == 8))  { return 0; }
  95.  
  96.          }
  97.  
  98.                      
  99. function curl_redir_exec($ch)
  100. {
  101. static $curl_loops = 0;
  102. static $curl_max_loops = 20;
  103. if ($curl_loops++ >= $curl_max_loops)
  104. {
  105. $curl_loops = 0;
  106. return FALSE;
  107. }
  108. curl_setopt($ch, CURLOPT_HEADER, true);
  109. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  110. $data = curl_exec($ch);
  111. list($header, $data) = explode("\n\n", $data, 2);
  112. $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  113. if ($http_code == 301 || $http_code == 302)
  114. {
  115. $matches = array();
  116. preg_match('/Location:(.*?)\n/', $header, $matches);
  117. $url = @parse_url(trim(array_pop($matches)));
  118. if (!$url)
  119. {
  120. //couldn't process the url to redirect to
  121. $curl_loops = 0;
  122. return $data;
  123. }
  124. $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
  125. if (!$url['scheme'])
  126. $url['scheme'] = $last_url['scheme'];
  127. if (!$url['host'])
  128. $url['host'] = $last_url['host'];
  129. if (!$url['path'])
  130. $url['path'] = $last_url['path'];
  131. $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:'');
  132. curl_setopt($ch, CURLOPT_URL, $new_url);
  133. //debug('Redirecting to', $new_url);
  134. return curl_redir_exec($ch);
  135. } else {
  136. $curl_loops=0;
  137. return $data;
  138. }
  139. }
  140.  
  141. function getPage($url)
  142. {
  143.         $ch = curl_init();
  144.         curl_setopt ($ch, CURLOPT_URL,$url);
  145.         curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
  146.         curl_setopt ($ch, CURLOPT_TIMEOUT, 1);
  147.         @curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
  148.         curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  149.         $result = curl_exec ($ch);
  150.         curl_close($ch);
  151.         return $result;
  152. }
  153.  
  154.  
  155. ?>
  156.  
  157. <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" align="left" width="100%">
  158. <tr>
  159. <td width="100%" style='padding-top: 7px; padding-bottom: 7px; padding-left: 10px; padding-right: 10px; '>
  160. Направление обмена:<br><br>
  161.   <form action="index.php" method="get" name="select_currency">
  162.   <select name="from" onchange="auto_direct(1, 0)">
  163.        
  164. <?php
  165.  
  166. $c1= $_GET["c1"];
  167. $c2= $_GET["c2"];
  168.  
  169. if ($c1=="" && $c2=="")
  170.  
  171. {$c1=1; $c2=2;}
  172.  
  173. foreach ($decode as $i=>$value)
  174. { if ($decode[$i] <>"") {echo"<option value=".$i;
  175. if ($i==$c1) {echo " selected";}
  176. echo ">".$decode[$i]."</option>";}
  177. }
  178.  
  179. ?>
  180. </select> на <select name="to" onchange="auto_direct(0, 1)">
  181.        
  182. <?php
  183. $i=0;
  184. foreach ($decode as $i=>$value)
  185. { if ($decode[$i] <>"") {echo"<option value=".$i;
  186. if ($i==$c2) {echo " selected";}
  187. echo ">".$decode[$i]."</option>";}
  188. }
  189.  
  190. ?>
  191.  
  192.  </select> <script language="JavaScript" type="text/javascript">
  193.    document.write('<a href="javascript:goto_list()"><b>Найти лучший курс!</b><'+'/a>');
  194.  </script>
  195.   <noscript>
  196.     <input type="submit" style="margin-top: 12px; margin-bottom: 2px" value="Найти курсы">
  197.   </noscript>
  198.  
  199. </form>
  200. </td>
  201. </tr>
  202. </table>
  203. <br>
  204. <h2>Обмен <?php echo $decode[$c1]; ?> на <?php echo $decode[$c2]; ?></h2><br><br>
  205. <div class="exchvar">
  206. &nbsp;&nbsp;<a href="http://pincode.biz.ua/index.php?c1=<?php echo $c2; ?>&c2=<?php echo $c1; ?>"><b>Обратный обмен</a></b> <a href="http://pincode.biz.ua/index.php?c1=1&c2=20"><b>Обмен WMZ на WMU</b></a> <a href="http://pincode.biz.ua/index.php?c1=2&c2=20"><b>Обмен WMR на WMU</b></a></div><br>
  207. <table cellSpacing="1" cellPadding="0" border="0" class="course" width="550">
  208.       <thead>
  209.       <tr class="caption"><td>&nbsp;Обменник</td><td width="90">Отдаете</td><td width="90">Получаете</td><td width="90" class="alignright">Резерв</td><td class="alignright" width="35">BL&nbsp;</td></tr>
  210.       </thead>
  211.       <tbody>
  212.  
  213. <?php
  214. $start = microtime(true);
  215. foreach ($obmennik as $k=>$valueo)
  216.  
  217. {$file = @getpage ($obmennik[$k]["kurs_url"]);
  218.  
  219. $file = explode(";", $file);
  220.  
  221. if ($obmennik[$k] <>"" && (!$file)==false)  
  222.  
  223.  {     
  224.         foreach ($file as $line_num => $file)
  225.         {
  226.        
  227.         $array = explode(",",trim($file,";"));
  228.         if ($c1==$array[0] && $c2==$array[1])
  229.  
  230.                 {
  231.                 $kursy[$k][1]=$array[2];
  232.                 $kursy[$k][2]=$array[3];
  233.                 if ($kursy[$k][1]<>"") {$nn=1; }
  234.                 }
  235.         }
  236. }
  237.  
  238. }
  239.  
  240. //if(is_array($kursy) && isset($kursy[1][1]))
  241. //foreach ($kursy as $kurs => $kursy) {
  242. //if ($kursy[$kurs][1]<>"" && $kursy[$kurs][2]<>"")
  243. // {$nn=1;}
  244. //}
  245. //if ($kursy[0][1]<>"")
  246. if ($nn==1)
  247.  
  248. {
  249. asort ($kursy);
  250.  
  251. $sum=0;
  252. $sk=0;
  253. $n=0;
  254. foreach($kursy as $key => $val)
  255.   {
  256.  
  257. $res=$kursy[$key][2];
  258. $print1=1;
  259. $print=$kursy[$key][1];
  260.          if ($print<1) {$print1=(1/$print);
  261. $print=1;
  262. }
  263.  
  264. $reserve=round($res,2);
  265. if ($reserve<=0) {$reserve=0;}
  266.  
  267. $wmid = @getpage('http://stats.wmtransfer.com/Levels/pWMIDLevel.aspx?wmid='.$obmennik[$key]["wmid"].'&w=35&h=18&bg=0XDBE2E9');
  268.    $img = @imagecreatefromstring($wmid);
  269.    for ($i = 4; $i < 35; $i++)
  270. {
  271. for ($j = 3; $j < 15; $j++)
  272. {
  273. $se[$i][$j] = (@imagecolorat ($img, $i, $j));
  274.         }
  275.          }
  276.          $is = false;
  277.          $w = '';
  278.  
  279.               if ( (itfalse(4) ==6 ) and (itfalse(5) ==7 ) and (itfalse(6) ==1 ) and (itfalse(7) ==2 ) and (itfalse(8) == 7 )  )
  280.             {
  281.               $is = true;
  282.               $w='no';
  283.             }
  284.  
  285.          if (!( itfalse(18) or itfalse(20) or itfalse(19) or ($is) ) )
  286.          {
  287.               //one digit
  288.  
  289.                   $p1 =  itfalse(23,$se);
  290.                   $p2 =   itfalse(28,$se);
  291.                   $w = (iscount($p1, $p2));
  292.                   $is = true;
  293.          }
  294.  
  295.          if ( ! ( itfalse(13) or itfalse(14) or itfalse(12) or ($is)  )   )
  296.          {
  297.               //two digit
  298.  
  299.                   $p1 =  itfalse(17,$se);
  300.                   $p2 =   itfalse(22,$se);
  301.                   $w = (iscount($p1, $p2));
  302.  
  303.                  $p1 =  itfalse(25,$se);
  304.                   $p2 =   itfalse(30,$se);
  305.                   $w .= (iscount($p1, $p2));
  306.                   $is = true;
  307.          }
  308.  
  309.           if (!( itfalse(7) or itfalse(8) or itfalse(6) or ($is) ) )
  310.          {
  311.  
  312.               //tree digit
  313.                    $p1 = itfalse(11,$se);
  314.                   $p2 =  itfalse(16,$se);
  315.                  $w  = (iscount2($p1, $p2));
  316.  
  317.                  $p1 =  itfalse(18,$se);
  318.                   $p2 =  itfalse(23,$se);
  319.                   $w.=(iscount2($p1, $p2));
  320.  
  321.                   $p1 =  itfalse(25,$se);
  322.                   $p2 =  itfalse(30,$se);
  323.                   $w.= (iscount2($p1, $p2));
  324.                    $is = true;
  325.          }
  326.          if ($is == false)
  327.          {
  328.  
  329.              $p1 = itfalse(6,$se);
  330.                   $p2 =  itfalse(11,$se);
  331.                   $w = (iscount2($p1, $p2));
  332.  
  333.                   $p1 = itfalse(13,$se);
  334.                   $p2 =  itfalse(18,$se);
  335.                   $w.= (iscount2($p1, $p2));
  336.  
  337.                   $p1 = itfalse(20,$se);
  338.                   $p2 =  itfalse(25,$se);
  339.                   $w.= (iscount2($p1, $p2));
  340.  
  341.                   $p1 = itfalse(27,$se);
  342.                   $p2 =  itfalse(32,$se);
  343.                   $w.= (iscount2($p1, $p2));
  344.          }
  345.                      
  346.  
  347. echo'      
  348. <tr class="row" onClick="f_cl('.$key.')">
  349. <td>&nbsp;'.$obmennik[$key]["name"].'</td>
  350. <td><b>'.number_format (round($print,2),2).'</b> '.$decode[$c1].'</td>
  351. <td><b>'.number_format (round($print1,2),2).'</b> '.$decode[$c2].'</td>
  352. <td class="alignright">'.number_format ($reserve,2).'</td>
  353. <td class="alignright">'.$w.'</td>
  354. </tr>';
  355.  
  356. $sum2=$sum2+$reserve;
  357. if ($print1==1){
  358. $sum1=$print*$reserve;
  359. }
  360. else {
  361. $sum1=$print1*$reserve;
  362. }
  363. $n=$n+1;
  364. $sum=$sum+$sum1;
  365. }
  366. $end = microtime(true);
  367. $time = date("H:i:s");
  368. echo '</tbody></table><br><br>';
  369. echo ('<h2>Статистика</h2><br>' );
  370. echo ('Всего обменных пунктов: <b>'.$n.'</b><br>' );
  371. echo ('Всего резервов: <b>'.number_format (round($sum2,2),2).' '.$decode[$c2].'</b><br>');
  372. echo ('Cредний курс <b>'.$decode[$c1].'/'.$decode[$c2].'</b> с учетом резервов: <b>'.number_format(round(($sum/$sum2),4),2).'</b><br>');
  373. echo ('Обновление: <b>'.$time.'</b><br>' );
  374. echo ('Время выполнения скрипта: <b>'.(round($end-$start, 4)).' c</b><br>');
  375. }
  376. else {echo '<tr><td></td></tr></tbody></table><br><b>Обмен в данном направлении не производится ни одним из имеющихся в базе обменных пунктов</b><br><br>';};
  377. ?>
  378. <br>
  379. </body>
  380. </html>
  381.  
  382.  


-----
 
 Top
Страниц (1): [1]
Сейчас эту тему просматривают: 0 (гостей: 0, зарегистрированных: 0)
« Напишите за меня, пожалуйста »


Все гости форума могут просматривать этот раздел.
Только зарегистрированные пользователи могут создавать новые темы в этом разделе.
Только зарегистрированные пользователи могут отвечать на сообщения в этом разделе.
 



Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB