| 1 |
<?php |
|---|
| 2 |
/********************************************************************************* |
|---|
| 3 |
|
|---|
| 4 |
** The contents of this file are subject to the vtiger CRM Public License Version 1.0 |
|---|
| 5 |
* ("License"); You may not use this file except in compliance with the License |
|---|
| 6 |
* The Original Code is: vtiger CRM Open Source |
|---|
| 7 |
* The Initial Developer of the Original Code is vtiger. |
|---|
| 8 |
* Portions created by vtiger are Copyright (C) vtiger. |
|---|
| 9 |
* All Rights Reserved. |
|---|
| 10 |
********************************************************************************/ |
|---|
| 11 |
|
|---|
| 12 |
require_once('class_http/class_http.php'); |
|---|
| 13 |
/** Function to get data from the external site |
|---|
| 14 |
* @param $url -- url:: Type string |
|---|
| 15 |
* @param $variable -- variable:: Type string |
|---|
| 16 |
* @returns $desc -- desc:: Type string array |
|---|
| 17 |
* |
|---|
| 18 |
*/ |
|---|
| 19 |
function getComdata($url,$variable="") |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
$h = new http(); |
|---|
| 23 |
$desc = array(); |
|---|
| 24 |
$h->dir = "class_http_dir/"; |
|---|
| 25 |
if (!$h->fetch($url, 2)) { |
|---|
| 26 |
echo "<h2>There is a problem with the http request!</h2>"; |
|---|
| 27 |
echo $h->log; |
|---|
| 28 |
exit(); |
|---|
| 29 |
} |
|---|
| 30 |
if($variable != "") |
|---|
| 31 |
{ |
|---|
| 32 |
$msft_stats = http::table_into_array($h->body, 'Find Symbol', 0, null); |
|---|
| 33 |
if($msft_stats != '') |
|---|
| 34 |
{ |
|---|
| 35 |
$desc=$msft_stats[0]; |
|---|
| 36 |
$data=getQuoteData($variable); |
|---|
| 37 |
if(is_array($data)) |
|---|
| 38 |
{ |
|---|
| 39 |
foreach($data as $key=>$value) |
|---|
| 40 |
array_push($desc,$value); |
|---|
| 41 |
return $desc; |
|---|
| 42 |
} |
|---|
| 43 |
else |
|---|
| 44 |
{ |
|---|
| 45 |
die; |
|---|
| 46 |
} |
|---|
| 47 |
} |
|---|
| 48 |
else |
|---|
| 49 |
return "Information on ".$variable." is not available or '".$variable."' is not a valid ticker symbol."; |
|---|
| 50 |
} |
|---|
| 51 |
else |
|---|
| 52 |
{ |
|---|
| 53 |
$headlines = array(); |
|---|
| 54 |
$news = http::table_into_array($h->body, 'HEADLINES',0, null); |
|---|
| 55 |
if(is_array($news)) |
|---|
| 56 |
{ |
|---|
| 57 |
$headlines[] = $news[35]; |
|---|
| 58 |
$headlines[] = $news[37]; |
|---|
| 59 |
$headlines[] = $news[39]; |
|---|
| 60 |
$headlines[] = $news[41]; |
|---|
| 61 |
return $headlines; |
|---|
| 62 |
} |
|---|
| 63 |
else |
|---|
| 64 |
return "No headlines available"; |
|---|
| 65 |
} |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
/** Function to get company quotes from external site |
|---|
| 69 |
* @param $var -- var:: Type string(company trickersymbol) |
|---|
| 70 |
* @returns $quote_data -- quote_data:: Type string array |
|---|
| 71 |
* |
|---|
| 72 |
*/ |
|---|
| 73 |
function getQuoteData($var) |
|---|
| 74 |
{ |
|---|
| 75 |
$url = "http://finance.yahoo.com/q?s=".$var; |
|---|
| 76 |
$h = new http(); |
|---|
| 77 |
$h->dir = "class_http_dir/"; |
|---|
| 78 |
if (!$h->fetch($url, 2)) { |
|---|
| 79 |
echo "<h2>There is a problem with the http request!</h2>"; |
|---|
| 80 |
echo $h->log; |
|---|
| 81 |
exit(); |
|---|
| 82 |
} |
|---|
| 83 |
$res_arr=array(); |
|---|
| 84 |
$quote_data = http::table_into_array($h->body, 'Delayed quote data', 0, null); |
|---|
| 85 |
if(is_array($quote_data)) |
|---|
| 86 |
{ |
|---|
| 87 |
array_shift($quote_data); |
|---|
| 88 |
array_shift($quote_data); |
|---|
| 89 |
if($quote_data[0][0]!= 'Last Trade:') |
|---|
| 90 |
array_shift($quote_data); |
|---|
| 91 |
} |
|---|
| 92 |
else |
|---|
| 93 |
{ |
|---|
| 94 |
die; |
|---|
| 95 |
} |
|---|
| 96 |
for($i=0;$i<16;$i++) |
|---|
| 97 |
{ |
|---|
| 98 |
if($quote_data !='') |
|---|
| 99 |
$res_arr[]=$quote_data[$i]; |
|---|
| 100 |
} |
|---|
| 101 |
return $res_arr; |
|---|
| 102 |
} |
|---|
| 103 |
?> |
|---|