Advertisement
machalda

Cetecho API search

Oct 7th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.22 KB | None | 0 0
  1. ///////////////////////////////////// SELECTORSEARCH()
  2. function selectorSearch($main, $second, $grain)
  3. {  
  4.    
  5.     $counter    = 0;
  6.     $resCounter = 0;
  7.     $jumpCount  = 40;
  8.     $jump       = 5; //51*5 = 255!!!
  9.     $jumpS      = 5; //51*5 = 255!!!
  10.     $vypisy     = false;
  11.     $g_limit    = 15; //pocet vystupu z hledani
  12.     $mainR      = hexdec($main[2].$main[3]);
  13.     $mainG      = hexdec($main[4].$main[5]);
  14.     $mainB      = hexdec($main[6].$main[7]);
  15.     $secondR    = hexdec($second[2].$second[3]);
  16.     $secondG    = hexdec($second[4].$second[5]);
  17.     $secondB    = hexdec($second[6].$second[7]);
  18.     $id         = array();
  19.     myLog("NEW SEARCH: MainColor:".$mainR." ".$mainG." ".$mainB." SecondColor:".$secondR." ".$secondG." ".$secondB." GrainType:".$grain." limit:".$g_limit);
  20.     $query = MySQL_Query("SELECT * FROM `content_type_page` WHERE field_group_name_value='$grain'") or die (mysql_error());    
  21.     while($result = mysql_fetch_array($query))
  22.     {
  23.         $pole["id"][$counter]       =   $result["nid"];
  24.        
  25.         $mainColor      =   explode(",", $result["field_dominant_color_value"]);
  26.         $secondColor    =   explode(",", $result["field_minority_color_value"]);
  27.        
  28.         $pole["mainR"][$counter]        =   $mainColor[0];
  29.         $pole["mainG"][$counter]        =   $mainColor[1];
  30.         $pole["mainB"][$counter]        =   $mainColor[2];
  31.        
  32.         $pole["secondR"][$counter]      =   $secondColor[0];
  33.         $pole["secondG"][$counter]      =   $secondColor[1];
  34.         $pole["secondB"][$counter]      =   $secondColor[2];
  35.        
  36.         $counter++;
  37.     }
  38.     if($vypisy) echo "MainColor:".$mainR." ".$mainG." ".$mainB." SecondColor:".$secondR." ".$secondG." ".$secondB." GrainType:".$grain."<br/>";
  39.     for($i=0;$i<=$jumpCount;$i++)
  40.     {  
  41.         $border     = $i*$jump;
  42.         $borderS    = $i*$jumpS;
  43.        
  44.         $borders["main_red_up"]         = $mainR + $border;
  45.         $borders["main_red_down"]       = $mainR - $border;
  46.         $borders["main_green_up"]       = $mainG + $border;
  47.         $borders["main_green_down"]     = $mainG - $border;
  48.         $borders["main_blue_up"]        = $mainB + $border;
  49.         $borders["main_blue_down"]      = $mainB - $border;
  50.         $borders["second_red_up"]       = $secondR + $borderS;
  51.         $borders["second_red_down"]     = $secondR - $borderS;
  52.         $borders["second_green_up"]     = $secondG + $borderS;
  53.         $borders["second_green_down"]   = $secondG - $borderS;
  54.         $borders["second_blue_up"]      = $secondB + $borderS;
  55.         $borders["second_blue_down"]    = $secondB - $borderS;
  56.        
  57.         foreach($borders as $key => $value)
  58.         {
  59.             if($value >= 255) $borders[$key]=255;
  60.             if($value <= 0) $borders[$key]=0;
  61.         }
  62.         for($x=0;$x<$counter;$x++)
  63.         {
  64.             $r_m = false;
  65.             $g_m = false;
  66.             $b_m = false;
  67.             $r_s = false;
  68.             $g_s = false;
  69.             $b_s = false;
  70.             $rgb_main = false;
  71.             $rgb_second = false;
  72.            
  73.             if(($pole["mainR"][$x] >= $borders["main_red_down"]) &&     ($pole["mainR"][$x] <= $borders["main_red_up"]))        $r_m    =    true;
  74.             if(($pole["mainG"][$x] >= $borders["main_green_down"]) && ($pole["mainG"][$x] <= $borders["main_green_up"]))    $g_m    =    true;
  75.             if(($pole["mainB"][$x] >= $borders["main_blue_down"]) &&    ($pole["mainB"][$x] <= $borders["main_blue_up"]))   $b_m    =    true;
  76.            
  77.             if(($pole["secondR"][$x] >= $borders["second_red_down"]) &&     ($pole["secondR"][$x] <= $borders["second_red_up"]))        $r_s    =    true;
  78.             if(($pole["secondG"][$x] >= $borders["second_green_down"]) && ($pole["secondG"][$x] <= $borders["second_green_up"]))    $g_s    =    true;
  79.             if(($pole["secondB"][$x] >= $borders["second_blue_down"]) &&    ($pole["secondB"][$x] <= $borders["second_blue_up"]))   $b_s    =    true;
  80.            
  81.             if(($r_m == true) && ($g_m == true) && ($b_m == true)) $rgb_main = true;
  82.             if(($r_s == true) && ($g_s == true) && ($b_s == true)) $rgb_second = true;
  83.            
  84.             if($vypisy)
  85.             {
  86.                 if($r_m) echo "<br/>J: ".$pole["mainR"][$x]." >= ".$borders["main_red_down"]." & ".$pole["mainR"][$x]." <= ".$borders["main_red_up"];
  87.                 else echo "<br/>N: ".$pole["mainR"][$x]." !> ".$borders["main_red_down"]." & ".$pole["mainR"][$x]." !< ".$borders["main_red_up"];
  88.                
  89.                 if($g_m) echo "<br/>J: ".$pole["mainG"][$x]." >= ".$borders["main_green_down"]." & ".$pole["mainG"][$x]." <= ".$borders["main_green_up"];
  90.                 else echo "<br/>N: ".$pole["mainG"][$x]." !> ".$borders["main_green_down"]." & ".$pole["mainG"][$x]." !< ".$borders["main_green_up"];
  91.                
  92.                 if($b_m) echo "<br/>J: ".$pole["mainB"][$x]." >= ".$borders["main_blue_down"]." & ".$pole["mainB"][$x]." <= ".$borders["main_blue_up"];
  93.                 else echo "<br/>N: ".$pole["mainB"][$x]." !> ".$borders["main_blue_down"]." & ".$pole["mainB"][$x]." !< ".$borders["main_blue_up"];
  94.                
  95.                 if($r_s) echo "<br/>J: ".$pole["secondR"][$x]." >= ".$borders["second_red_down"]." & ".$pole["secondR"][$x]." <= ".$borders["second_red_up"];
  96.                 else echo "<br/>N: ".$pole["secondR"][$x]." !> ".$borders["second_red_down"]." & ".$pole["secondR"][$x]." !< ".$borders["second_red_up"];
  97.                
  98.                 if($g_s) echo "<br/>J: ".$pole["secondG"][$x]." >= ".$borders["second_green_down"]." & ".$pole["secondG"][$x]." <= ".$borders["second_green_up"];
  99.                 else echo "<br/>N: ".$pole["secondG"][$x]." !> ".$borders["second_green_down"]." & ".$pole["secondG"][$x]." !< ".$borders["second_green_up"];
  100.                
  101.                 if($b_s) echo "<br/>J: ".$pole["secondB"][$x]." >= ".$borders["second_blue_down"]." & ".$pole["secondB"][$x]." <= ".$borders["second_blue_up"];
  102.                 else echo "<br/>N: ".$pole["secondB"][$x]." !> ".$borders["second_blue_down"]." & ".$pole["secondB"][$x]." !< ".$borders["second_blue_up"];
  103.             }
  104.             if(($rgb_main == true) && ($rgb_second == true))
  105.             {
  106.                 array_push($id, $pole["id"][$x]);
  107.                 $pole["mainR"][$x] = 666;
  108.                 if($vypisy)
  109.                 {
  110.                     echo "<br/> NALEZEN!!!!!";
  111.                     echo $pole["id"][$x]." Xko: ".$x."ResC: ".$resCounter."<br/>";
  112.                     echo "<br/>";
  113.                 }
  114.             }
  115.         }
  116.     }
  117.     foreach($id as $v)
  118.     {
  119.         $query = MySQL_Query("SELECT nid, body FROM `content_type_page` LEFT JOIN `node_revisions` USING(nid) WHERE nid='$v' LIMIT 1") or die (mysql_error());     
  120.         $row = mysql_fetch_assoc($query);
  121.        
  122.         $ret = $row['body'];
  123.         //ziskani image URL
  124.         if(StrriPos($ret, "src=\"")===false) myLog("ImageUrl not found. Brand: ".$brandName." Nid: ".$row['nid ']);
  125.         else
  126.         {
  127.             $ret=ereg_replace(".*src=\"", "", $ret);
  128.             $ret=ereg_replace("\".*", "", $ret);
  129.             $imageUrl=$ret;
  130.         }
  131.         $pom=$pom."-#-".$v;
  132.         $pom=$pom."-#-".$imageUrl."<br/>";
  133.     }
  134.     //$output = implode(", ", $id);
  135.     $output = $pom;
  136.     //$output = "<br/><br/><br/>konec";
  137.     return $output;
  138. };
  139. ///////////////////////////////////// END OF SELECTORSEARCH()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement