Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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