Subversion Repositories SmartDukaan

Rev

Rev 10582 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10582 lgm 1
<?php
2
if (!defined('BASEPATH'))
3
	exit('No direct script access allowed');
4
 
5
 
6
/*
7
 * Model for home
8
 */ 
9
 
10
 
11
Class Oauth_model extends CI_Model {
12
 
13
	var $url = '';
14
	var $parser_model;
15
	var $parser;
16
	var $current_client;
17
 
18
	function __construct() {
19
 
20
		// Call the Model constructor
21
		parent::__construct();
22
		//load appropriate parser
23
		$current_client =$this -> config -> item('current_client');
24
		$model = $current_client.'_model';
25
		$this->load->model($model);
26
		$this->parser = $this-> $model;
27
		$this->current_client=$this -> config -> item('current_client');
28
 
29
 
30
	}
31
 
32
 
33
	function getLogin($get=array(),$post=array(),$module=array())
11049 lgm 34
	{	
10582 lgm 35
		$output =array();
36
		if(isset($module) and !empty($module))
37
		{
38
			if(isset($module['header']) and !empty($module['header']))
39
			{
40
				foreach($module['header'] as $header)
41
				{
11049 lgm 42
					$cache = getFileCache($header);
43
					if(isset($cache) && !empty($cache)){
44
						$head['header'][$header] = $cache;
45
					}else{
46
						$this->curlURL($header,'get');	
47
					}
10582 lgm 48
				}
49
			}
50
			if(isset($module['footer']) and !empty($module['footer']))
51
			{
52
				foreach($module['footer'] as $footer)
53
				{
11049 lgm 54
					$cache = getFileCache($header);
55
					if(isset($cache) && !empty($cache)){
56
						$foot['footer'][$footer] = $cache;
57
						//echo '<br/>';
58
					}else{
59
						$this->curlURL($footer,'get');	
60
					}
10582 lgm 61
				}
62
			}
63
			if(isset($module['response']) and !empty($module['response']))
64
			{
65
				foreach($module['response'] as $response)
66
				{
67
					if(isset($post) and !empty($post))
68
					{
69
						if($this->current_client=='prestashop' || $this->current_client=='magento' )
70
						$this->curlURL($response,'post',$post);
71
					else
72
						$this->curlURL($response,'post',$post);
73
 
74
					}
75
				}
76
			}
77
 
78
 
79
		}
80
 
81
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
82
		//$this->curlURL('products','get',$get);
83
		$responses = $this->mcurl->execute();
84
		if(isset($responses) and !empty($responses))
85
		$responses = $this->parser->parse_response($responses,$module);
11049 lgm 86
		if(isset($head) && !empty($head)){
87
			foreach($head['header'] as $key=>$value){
88
				$responses['header'][$key] = $value;
89
			}
90
		}
91
		if(isset($foot) && !empty($foot)){
92
			foreach($foot['footer'] as $key=>$value){
93
				$responses['footer'][$key] = $value;
94
			}
95
		}
10582 lgm 96
		return $responses;
97
	}
98
	function getSignup($get=array(),$post=array(),$module=array())
99
	{
100
		$output =array();
101
		if(isset($module) and !empty($module))
102
		{
103
			if(isset($module['header']) and !empty($module['header']))
104
			{
105
				foreach($module['header'] as $header)
106
				{
11049 lgm 107
					$cache = getFileCache($header);
108
					if(isset($cache) && !empty($cache)){
109
						$head['header'][$header] = $cache;
110
					}else{
111
						$this->curlURL($header,'get');	
112
					}
10582 lgm 113
				}
114
			}
115
			if(isset($module['footer']) and !empty($module['footer']))
116
			{
117
				foreach($module['footer'] as $footer)
118
				{
11049 lgm 119
					$cache = getFileCache($header);
120
					if(isset($cache) && !empty($cache)){
121
						$foot['footer'][$footer] = $cache;
122
						//echo '<br/>';
123
					}else{
124
						$this->curlURL($footer,'get');	
125
					}
10582 lgm 126
				}
127
			}
128
			if(isset($module['response']) and !empty($module['response']))
129
			{
130
				foreach($module['response'] as $response)
131
				{
132
					if(isset($post) and !empty($post))
133
					{
134
						if($this->current_client=='prestashop' || $this->current_client=='magento' )
135
						$this->curlURL($response,'post',$post);
136
					else
137
						$this->curlURL($response,'post',$post);
138
 
139
					}
140
				}
141
			}
142
 
143
 
144
		}
145
 
146
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
147
		//$this->curlURL('products','get',$get);
148
		$responses = $this->mcurl->execute();
149
		if(isset($responses) and !empty($responses))
150
		$responses = $this->parser->parse_response($responses,$module);
11049 lgm 151
		if(isset($head) && !empty($head)){
152
			foreach($head['header'] as $key=>$value){
153
				$responses['header'][$key] = $value;
154
			}
155
		}
156
		if(isset($foot) && !empty($foot)){
157
			foreach($foot['footer'] as $key=>$value){
158
				$responses['footer'][$key] = $value;
159
			}
160
		}
10582 lgm 161
		return $responses;
162
	}
163
function curlURL($configurl=null,$methodtype='get',$parameter=array())
164
{
11049 lgm 165
 
10582 lgm 166
		$params ='';
167
		$display='';
168
		$url = $this->config->item('curl_base_url');
169
		$productsurl =$this->config->item($configurl);
170
		if(isset($productsurl['url']) and !empty($productsurl['url']))
171
			{
172
				$url .=$productsurl['url'];
173
				if($productsurl['display'])
174
				{$display=$productsurl['display'];}
175
			if(empty($parameter)){$parameter=$productsurl['params'];}
176
 
177
 
178
		if(isset($parameter) and !empty($parameter) and $methodtype=='get')
179
		{
180
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
181
 
182
		}
183
		if(isset($parameter) and !empty($parameter) and $methodtype=='post')
184
		{
185
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
186
			$methodtype ='post';
187
		}
188
		if(!isset($parameter) || empty($parameter))
189
			{$params =$this->parser->prepareParams('',$display,$configurl);}
190
		//$methodtype = 'post';
191
		return $this->mcurl->add_call($configurl,$methodtype,$url,$params);
192
	}
193
	else
194
		{return '';}
195
 
196
}
197
 
198
 
199
}