colonymech / docs / www / colonyscout / internal / includes / inventoryFunctions.php @ f59acf11
History | View | Annotate | Download (2.02 KB)
1 |
<?php
|
---|---|
2 |
include($docRoot.'internal/simple_html_dom.php'); |
3 |
|
4 |
function getSourceDigikey($partnumber) { |
5 |
return file_get_html(getURL($partnumber,"Digikey"))->find('div#content',0); |
6 |
} |
7 |
|
8 |
function getSourceSparkfun($partnumber,$type) { |
9 |
$result = file_get_html(getURL($partnumber,"SparkFun")); |
10 |
if($type==0) { |
11 |
return $result->find('div#price',0); |
12 |
} else {
|
13 |
return $result->find('div.span-3',0); |
14 |
} |
15 |
} |
16 |
|
17 |
function getPriceDigikey($partnumber) { |
18 |
$html=getSourceDigikey($partnumber); |
19 |
|
20 |
//filter out bad part numbers
|
21 |
preg_match('/Part not found/', $html->plaintext, $matches, PREG_OFFSET_CAPTURE); |
22 |
if(count($matches)>0) return 0; //return if "part not found" is in body |
23 |
|
24 |
//0 == the price table formatted html
|
25 |
//1 == part price1
|
26 |
//2 == part price1*qty1
|
27 |
$price = $html->find('td[align=right]'); |
28 |
$qty = $html->find('td[align=center]'); |
29 |
|
30 |
$price_table;
|
31 |
for($i=0;$i<3;$i++){ |
32 |
$price_table[$qty[$i]->innertext] = strip_tags($price[2*$i+2]); |
33 |
} |
34 |
|
35 |
return $price_table; |
36 |
} |
37 |
|
38 |
function getPriceSparkfun($partnumber) { |
39 |
$html = getSourceSparkfun($partnumber,0); |
40 |
|
41 |
if(!$html) return 0; |
42 |
|
43 |
$price = $html->find('table.pricing',0); |
44 |
$t = $price->find('th[style="font-weight: normal;"]'); |
45 |
$s = $price->find('th'); |
46 |
|
47 |
$price_table[1]=str_replace("$","",$s[2]->innertext); //qty 1 |
48 |
$price_table[10]=str_replace("$","",$t[0]->innertext); //qty 10 |
49 |
$price_table[100]=str_replace("$","",$t[1]->innertext); //qty 100 |
50 |
|
51 |
return $price_table; |
52 |
} |
53 |
|
54 |
function getThumbDigikey($partnumber) { |
55 |
$img = getThumbFromDisk($partnumber); //if we have a cached version, use it |
56 |
if ($img) { return $img;} |
57 |
|
58 |
$html=getSourceDigikey($partnumber); |
59 |
$imgs = $html->find('img',0); |
60 |
return ($imgs) ? $imgs->src : 0; |
61 |
} |
62 |
|
63 |
function getThumbSparkfun($partnumber) { |
64 |
$img = getThumbFromDisk($partnumber); //if we have a cached version, use it |
65 |
if ($img) { return $img;} |
66 |
|
67 |
$html = getSourceSparkfun($partnumber,1); |
68 |
if(!$html) return 0; |
69 |
|
70 |
$imgs = $html->find('a[rel="lightbox[product]"]',1); |
71 |
return ($imgs) ? $imgs->href : 0; //ternary operator, if $imgs is not an object, return 0, otherwise return $imgs->href |
72 |
} |
73 |
|
74 |
|
75 |
?>
|