Subversion Repositories SmartDukaan

Rev

Rev 10582 | Rev 10810 | 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
 
3
 
4
if(!function_exists('getCache'))
5
{
6
 
7
	function getCache($module=array(),$restriction=array())
8
	{
9
		$CI =& get_instance();
10
		$CI->load->library(array('cache'));
11
		$returnresponse =array();
12
		if(isset($module) and !empty($module))
13
		{
14
			if(isset($module['header']) and !empty($module['header']) and in_array('header', $restriction))
15
			{
16
				$headerdata =array();
17
				foreach($module['header'] as $key=>$header)
18
				{
19
 
20
					$cache = $CI->cache->get($header);
21
					if(isset($cache) and !empty($cache))
22
					{ $headerdata[$header]=$cache;
23
					unset($module['header'][$key]);	
24
 
25
					}
26
 
27
				}
28
				$returnresponse['header']=$headerdata;
29
			}
30
			if(isset($module['footer']) and !empty($module['footer']) and in_array('footer', $restriction))
31
			{
32
				$footerdata =array();
33
				foreach($module['footer'] as $key=>$footer)
34
				{
35
					$cache = $CI->cache->get($footer);
36
					if(isset($cache) and !empty($cache))
37
					{$footerdata[$footer]=$cache;
38
					 unset($module['footer'][$key]);	
39
					}
40
 
41
				}
42
				$returnresponse['footer']=$footerdata;
43
			}
44
			if(isset($module['response']) and !empty($module['response']) and in_array('response', $restriction))
45
			{
46
				$responsedata =array();
47
				foreach($module['response'] as $key=>$response)
48
				{
49
					$cache = $CI->cache->get($response);
50
					if(isset($cache) and !empty($cache))
51
					{
52
						$responsedata[$response]=$cache;
53
					 	unset($module['response'][$key]);	
54
					}
55
				}
56
				$returnresponse['response']=$responsedata;
57
			}
58
 
59
		$returnresponse['module']=$module;	
60
 
61
 
62
		}
63
 
64
 
65
		return $returnresponse;
66
 
67
	}
68
 
69
}
70
if(!function_exists('setCache'))
71
{
72
 
73
	function setCache($module=array(),$restriction=array(),$data=array())
74
	{
75
 
76
		$CI =& get_instance();
77
		$CI->load->library(array('cache'));
78
		if(isset($module) and !empty($module))
79
		{
80
			if(isset($module['header']) and !empty($module['header']) and in_array('header', $restriction))
81
			{
82
 
83
				foreach($module['header'] as $header)
84
				{
10721 lgm 85
					$CI->cache->write($data['header'][$header], $header,600);
10582 lgm 86
 
87
				}
88
 
89
			}
90
			if(isset($module['footer']) and !empty($module['footer']) and in_array('footer', $restriction))
91
			{
92
				foreach($module['footer'] as $footer)
93
				{
10721 lgm 94
					$CI->cache->write($data['footer'][$footer], $footer,600);
10582 lgm 95
 
96
				}
97
 
98
			}
99
			if(isset($module['response']) and !empty($module['response']) and in_array('response', $restriction))
100
			{
101
 
102
				foreach($module['response'] as $response)
103
				{
104
					if($response != 'recommended_accessories'){
10721 lgm 105
						$CI->cache->write($data['response'][$response], $response,600);
10582 lgm 106
					}
107
				}
108
 
109
			}
110
 
111
 
112
 
113
		}
114
 
115
 
116
		return true;
117
 
118
 
119
 
120
	}
121
 
122
}
123
if(!function_exists('setFileCache'))
124
{
125
 
126
	function setFileCache($content=null,$filename=null,$expires=null)
127
	{
128
		$CI =& get_instance();
129
		$CI->load->library(array('cache'));
130
		if(isset($content) && ($content != null))
131
		{
132
			$CI->cache->write($content, $filename,$expires);
133
		}
134
		return true;
135
	}
136
 
137
}
138
if(!function_exists('getFileCache'))
139
{
140
 
141
	function getFileCache($filename=null)
142
	{
143
 
144
		$CI =& get_instance();
145
		$CI->load->library(array('cache'));
146
		$returnresponse =array();
147
		if(isset($filename) && ($filename != null))
148
		{
149
			$cache = $CI->cache->get($filename);
150
			if(isset($cache) && !empty($cache)){
151
				$returnresponse = $cache;
152
			}
153
		}
154
		return $returnresponse;
155
	}
156
 
157
}
158
 
159
 
160
//share helper start here
161
 
162
if( !function_exists('share_check') ){
163
	/**
164
	 * Check type of share and return $URL or FALSE
165
	 * 
166
	 * @param	string $type	type of share
167
	 * @return	string|bool
168
	 */
169
	function share_check( $type='' ){
170
		$url = array(
171
			'twitter'	=> 'http://twitter.com/share',
172
			'facebook'	=> 'http://facebook.com/sharer.php',
173
			'buzz'		=> 'http://www.google.com/buzz/post',
174
			'vkontakte'	=> 'http://vkontakte.ru/share.php',
175
		);
176
		return (isset($url[$type])) ? $url[$type] : FALSE;
177
	}
178
}
179
 
180
if( !function_exists('share_url') ){
181
	/**
182
	 * Generate url for share at some social networks
183
	 *
184
	 * @param	string $type	type of share
185
	 * @param	array $args		parameters for share
186
	 * @return	string
187
	 */
188
	function share_url( $type='', $args=array() ){
189
		$url = share_check( $type );
190
		if( $url === FALSE ){
191
			log_message( 'debug', 'Please check your type share_url('.$type.')' );
192
			return "#ERROR-check_share_url_type";
193
		}
194
 
195
		$params = array();
196
		if( $type == 'twitter' ){
197
			foreach( explode(' ', 'url via text related count lang counturl') as $v ){
198
				if( isset($args[$v]) ) $params[$v] = $args[$v];
199
			}
200
		}elseif( $type == 'facebook' ){
201
			$params['u']		= $args['url'];
202
			$params['t']		= $args['text'];
203
		}elseif( $type == 'buzz'){
204
			$params['url']		= $args['url'];
205
			$params['imageurl']	= $args['image'];
206
			$params['message']	= $args['text'];
207
		}elseif( $type == 'vkontakte'){
208
			$params['url']		= $args['url'];
209
		}
210
 
211
		$param = '';
212
		foreach( $params as $k=>$v ) $param .= '&'.$k.'='.urlencode($v);
213
		return $url.'?'.trim($param, '&');
214
	}
215
}
216
 
217
if( !function_exists('share_button') ){
218
	/**
219
	 * Generate buttons for share at some social networks
220
	 *
221
	 * @param	string $type	type of share
222
	 * @param	array $args		parameters for share
223
	 * @return string
224
	 */
225
	function share_button( $type='', $args=array() ){
226
		$url = share_check( $type );
227
		if( $url === FALSE ){
228
			log_message( 'debug', 'Please check your type share_button('.$type.')' );
229
			return "#ERROR-check_share_button_type";
230
		}
231
 
232
		$params = array();
233
		$param	= '';
234
 
235
		if( $type == 'twitter'){
236
			if( isset($args['iframe']) ){
237
				$url = share_url( $type, $args );
238
				list($url, $param) = explode('?', $url);
239
				$button = <<<DOT
240
				<iframe allowtransparency="true" frameborder="0" scrolling="no" style="width:130px; height:50px;"
241
				src="http://platform.twitter.com/widgets/tweet_button.html?{$param}"></iframe>
242
DOT;
243
			}else{
244
				foreach( explode(' ', 'url via text related count lang counturl') as $v ){
245
					if( isset($args[$v]) ) $params[] = 'data-'.$v.'="'.$args[$v].'"';
246
				}
247
				$param = implode( ' ', $params );
248
				$button = <<<DOT
249
				<a href="http://twitter.com/share" class="twitter-share-button" {$param}>Tweet</a>
250
				<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
251
DOT;
252
			}
253
		}elseif( $type == 'facebook' ){
254
			if( !isset($args['type']) ) $args['type'] = 'button_count';
255
			if( isset($args['fb']) ){
256
				$params = array( 'type'=>'type', 'href'=>'url', 'class'=>'class' );
257
				foreach( $params as $k=>$v ){
258
					if( isset($args[$v]) ) $param .= $k.'="'.$args[$v].'"';
259
				}
260
				$button = "<fb:share-button {$param}></fb:share-button>";
261
			}else{
262
				$params = array( 'type'=>'type', 'share_url'=>'url' );
263
				foreach( $params as $k=>$v ){
264
					if( isset($args[$v]) ) $param .= $k.'="'.$args[$v].'"';
265
				}
266
				if( !isset($args['button_text']) ) $args['button_text'] = 'Share to Facebook';
267
				$button = <<<DOT
268
				<a name="fb_share" {$param}>{$args['button_text']}</a>
269
				<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
270
DOT;
271
			}
272
		}elseif( $type == 'buzz' ){
273
			$params = array( 'button-style'=>'type', 'local'=>'lang', 'url'=>'url', 'imageurl'=>'image');
274
			foreach( $params as $k=>$v ){
275
				if( isset($args[$v]) ) $param .= ' data-'.$k.'="'.$args[$v].'"';
276
			}
277
			if( !isset($args['title']) ) $args['title'] = 'Share to Google Buzz';
278
			$button = <<<DOT
279
			<a title="{$args['title']}" class="google-buzz-button" href="http://www.google.com/buzz/post" {$param}></a>
280
			<script type="text/javascript" src="http://www.google.com/buzz/api/button.js"></script>
281
DOT;
282
		}elseif( $type == 'vkontakte' ){
283
			$url = isset($args['url']) ? '{url: "'.$args['url'].'"}' : 'false';
284
			foreach( explode(' ', 'type text') as $v ){
285
				if( isset($args[$v]) ) $param[] = $k.': "'.urlencode($args[$v]).'"';
286
			}
287
			$param = implode( ', ', $params );
288
			if( !empty($param) ) $param = ', {'.$param.'}';
289
			$button = <<<DOT
290
			<script type="text/javascript" src="http://vkontakte.ru/js/api/share.js?9" charset="windows-1251"></script>
291
			<script type="text/javascript">document.write(VK.Share.button({$url}{$param}));</script>
292
DOT;
293
		}
294
		return $button;
295
	}
296
}
297
//end of share helper
298
 
299
if (!function_exists('getChecksum')) {
300
	function getChecksum($MerchantId, $OrderId, $Amount, $redirectUrl, $WorkingKey)  {
301
		$str = "$MerchantId|$OrderId|$Amount|$redirectUrl|$WorkingKey";
302
		$adler = 1;
303
		$adler = adler32($adler,$str);
304
		return $adler;
305
	}
306
}
307
if (!function_exists('adler32')) {
308
	function adler32($adler , $str)
309
	{
310
		$BASE =  65521 ;
311
 
312
		$s1 = $adler & 0xffff ;
313
		$s2 = ($adler >> 16) & 0xffff;
314
		for($i = 0 ; $i < strlen($str) ; $i++)
315
		{
316
			$s1 = ($s1 + Ord($str[$i])) % $BASE ;
317
			$s2 = ($s2 + $s1) % $BASE ;
318
		}
319
		return leftshift($s2 , 16) + $s1;
320
	}
321
}
322
if(!function_exists('leftshift')){
323
	function leftshift($str , $num)
324
	{
325
 
326
		$str = DecBin($str);
327
 
328
		for( $i = 0 ; $i < (64 - strlen($str)) ; $i++)
329
			$str = "0".$str ;
330
 
331
		for($i = 0 ; $i < $num ; $i++) 
332
		{
333
			$str = $str."0";
334
			$str = substr($str , 1 ) ;
335
			//echo "str : $str <BR>";
336
		}
337
		return cdec($str) ;
338
	}
339
}
340
if (!function_exists('cdec')) {
341
 
342
	function cdec($num)
343
	{
344
		$dec=0;
345
		for ($n = 0 ; $n < strlen($num) ; $n++)
346
		{
347
		   $temp = $num[$n] ;
348
		   $dec =  $dec + $temp*pow(2 , strlen($num) - $n - 1);
349
		}
350
 
351
		return $dec;
352
	}
353
}
354
if (!function_exists('verifyChecksum')) {
355
	function verifyChecksum($MerchantId , $OrderId, $Amount, $AuthDesc, $WorkingKey,  $CheckSum)
356
	{	
357
		$str = "";
358
		$str = "$MerchantId|$OrderId|$Amount|$AuthDesc|$WorkingKey";
359
		$adler = 1;
360
		$adler = adler32($adler,$str);
361
		if($adler==$CheckSum) return true;
362
		else return false;		
363
	}
364
}
365
 
366
 
367
?>