class models_DBCurrencyRate extends models_DBEntity{
public function __construct($id = null)
{
parent::__construct(new models_DBTable_CurrencyRate(),$id);
}
public function getcurrencyrate()
{
// add new one
$eurrate=1; $ilsrate=1; $gbprate=1; $result=array();
$c_array = array("EUR", "ILS", "GBP");
$url = "http://www.currencyconverterapi.com/api/v3/convert?q=USD_EUR,USD_ILS,USD_GBP&compact=ultra&apiKey=11e78efe-7fb5-40b3-b728-b1461238fdfd";
$request = curl_init();
$timeOut = 0;
curl_setopt ($request, CURLOPT_URL, $url);
curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut);
$response = curl_exec($request);
curl_close($request);
$json_a=json_decode($response,true);
if($json_a['USD_EUR']==0) return 1;
echo $json_a['USD_EUR']."
";
echo $json_a['USD_ILS']."
";
echo $json_a['USD_GBP']."
";
/*
$regularExpression = '#\(.+?)\<\/span\>#s';
preg_match($regularExpression, $response, $finalData);
$result[$i] = 1.015*preg_replace("/[^0-9.]/", '', $finalData[0]);
echo $c_array[$i].": ".$result[$i]."
";
sleep(1);
*/
date_default_timezone_set('Asia/Jerusalem');
$this->datetime = date("Y-m-d H:i:s");
$this->usd = 1.0;
$correction_factor=1.035;
$this->eur = $correction_factor*$json_a['USD_EUR'];
$this->ils = $correction_factor*$json_a['USD_ILS'];
$this->gbp = $correction_factor*$json_a['USD_GBP'];
$this->save();
return 1;
}
public function fetchcurrencyrate($curr)
{
$select = $this->_dbTable->select();
$select->setIntegrityCheck(false);
$select = $select->from($this->_dbTable, array($curr))
->order("autonum DESC")
->limit(1);
//echo (string)$select;
$res = $this->_dbTable->fetchAll($select);
return $res;
}
}
?>
class models_DBVisitors extends models_DBEntity{
public function __construct($id = null)
{
parent::__construct(new models_DBTable_Visitors(),$id);
}
public function get_ip() {
//Just get the headers if we can or else use the SERVER global
if ( function_exists( 'apache_request_headers' ) ) {
$headers = apache_request_headers();
} else {
$headers = $_SERVER;
}
//Get the forwarded IP if it exists
if ( array_key_exists( 'X-Forwarded-For', $headers ) && filter_var( $headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) {
$the_ip = $headers['X-Forwarded-For'];
} elseif ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $headers ) && filter_var( $headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 )
) {
$the_ip = $headers['HTTP_X_FORWARDED_FOR'];
} else {
$the_ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 );
}
return $the_ip;
}
// returns which A/B testing version to use (1 or 2)
// if record is missed in visitors table, then it will add it and choose random version
public function addVisitor()
{
$ip = ip2long($this->get_ip());
$select = $this->_dbTable->select();
$select = $select->from(array('v' => 'visitors'), array('visitor_id', 'ip_addr', 'ab_version', 'utm_source', 'utm_medium', 'utm_term', 'utm_content', 'utm_campaign', 'HTTP_REFERER'))
->where("v.ip_addr = '$ip'");
$res = $this->_dbTable->fetchAll($select);
if (count($res)==1)
{
return $res[0]['ab_version'];
}else
{
$utm_source=NULL;
$utm_medium=NULL;
$utm_term=NULL;
$utm_content=NULL;
$utm_campaign=NULL;
$keyword=NULL;
$matchtype=NULL;
$HTTP_REFERER=NULL;
if(isset($_GET['utm_source'])) {
$utm_source=$_GET['utm_source'];
} else if(isset($_REQUEST['utm_source'])) {
$utm_source=$_REQUEST['utm_source'];
}
if(isset($_GET['utm_medium'])) $utm_medium=$_GET['utm_medium'];
else if(isset($_REQUEST['utm_medium'])) $utm_medium=$_REQUEST['utm_medium'];
if(isset($_GET['utm_term'])) $utm_term=$_GET['utm_term'];
else if(isset($_REQUEST['utm_term'])) $utm_term=$_REQUEST['utm_term'];
if(isset($_GET['utm_content'])) $utm_content=$_GET['utm_content'];
else if(isset($_REQUEST['utm_content'])) $utm_content=$_REQUEST['utm_content'];
if(isset($_GET['utm_campaign'])) $utm_campaign=$_GET['utm_campaign'];
else if(isset($_REQUEST['utm_campaign'])) $utm_campaign=$_REQUEST['utm_campaign'];
if(isset($_GET['keyword'])) $keyword=$_GET['keyword'];
else if(isset($_REQUEST['keyword'])) $keyword=$_REQUEST['keyword'];
if(isset($_GET['matchtype'])) $matchtype=$_GET['matchtype'];
else if(isset($_REQUEST['matchtype'])) $matchtype=$_REQUEST['matchtype'];
if(isset($_GET['HTTP_REFERER'])) $HTTP_REFERER=$_GET['HTTP_REFERER'];
else if(isset($_SERVER['HTTP_REFERER'])) $HTTP_REFERER=$_SERVER['HTTP_REFERER'];
$out=parse_url($HTTP_REFERER);
if(isset($out['query'])) {
parse_str($out['query'],$out2);
if(isset($out2['utm_source'])) $utm_source=$out2['utm_source'];
if(isset($out2['utm_medium'])) $utm_medium=$out2['utm_medium'];
if(isset($out2['utm_term'])) $utm_term=$out2['utm_term'];
if(isset($out2['utm_content'])) $utm_content=$out2['utm_content'];
if(isset($out2['utm_campaign'])) $utm_campaign=$out2['utm_campaign'];
if(isset($out2['keyword'])) $keyword=$out2['keyword'];
}
// add new one
$ab_ver = 2;//rand() % 2 + 1;
$this->ip_addr = $ip;
$this->ab_version = $ab_ver;
$this->utm_source = $utm_source;
$this->utm_medium = $utm_medium;
$this->utm_term = $utm_term;
$this->utm_content = $utm_content;
$this->utm_campaign = $utm_campaign;
$this->keyword = $keyword;
$this->matchtype = $matchtype;
$this->HTTP_REFERER = $HTTP_REFERER;
$this->save();
return $ab_ver;
}
}
}
Fatal error: Uncaught Error: Class 'models_DBVisitors' not found in /var/www/vhosts/olddisk/var/www/vhosts/smartlation.com/sandbox.smartlation.com/application/controllers/IndexController.php:96
Stack trace:
#0 /var/www/vhosts/olddisk/var/www/vhosts/smartlation.com/sandbox.smartlation.com/library/Zend/Controller/Action.php(516): IndexController->indexAction()
#1 /var/www/vhosts/olddisk/var/www/vhosts/smartlation.com/sandbox.smartlation.com/library/Zend/Controller/Dispatcher/Standard.php(308): Zend_Controller_Action->dispatch()
#2 /var/www/vhosts/olddisk/var/www/vhosts/smartlation.com/sandbox.smartlation.com/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch()
#3 /var/www/vhosts/olddisk/var/www/vhosts/smartlation.com/sandbox.smartlation.com/library/Zend/Application/Bootstrap/Bootstrap.php(105): Zend_Controller_Front->dispatch()
#4 /var/www/vhosts/olddisk/var/www/vhosts/smartlation.com/sandbox.smartlation.com/library/Zend/Application.php(384): Zend_Application_Bootstrap_Bootstrap->run()
#5 in /var/www/vhosts/olddisk/var/www/vhosts/smartlation.com/sandbox.smartlation.com/application/controllers/IndexController.php on line 96