Subversion Repositories SmartDukaan

Rev

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