7
7
use AppArena \Models \Environment \AbstractEnvironment ;
8
8
use AppArena \Models \Environment \Facebook ;
9
9
use AppArena \Models \Environment \Website ;
10
+ use Exception ;
11
+ use Mustache_Engine ;
12
+ use Mustache_Loader_FilesystemLoader ;
10
13
11
14
/**
12
15
* SmartLink class which handles user redirects for the app
@@ -57,7 +60,7 @@ class SmartLink {
57
60
* @param AbstractEnvironment $environment Environment the app is currently running in
58
61
* @param Cache $cache Cache adapter for managing the link shortener
59
62
*
60
- * @throws \ Exception When no app ID is passed
63
+ * @throws Exception When no app ID is passed
61
64
*/
62
65
public function __construct ( AbstractEntity $ entity , Environment $ environment , Cache $ cache ) {
63
66
// Initialize the base url
@@ -67,7 +70,7 @@ public function __construct( AbstractEntity $entity, Environment $environment, C
67
70
$ this ->environment = $ environment ;
68
71
$ this ->entity = $ entity ;
69
72
if ( ! $ this ->entity ) {
70
- throw ( new \ Exception ( 'No app id available ' ) );
73
+ throw ( new Exception ( 'No app id available ' ) );
71
74
}
72
75
$ this ->cookie_key = AppManager::COOKIE_KEY . $ this ->getEntity ()->getId ();
73
76
@@ -268,14 +271,12 @@ public function getParams( $includeExpired = false ) {
268
271
return $ params ;
269
272
}
270
273
271
- /**
272
- * Sets values to the SmartCookie
273
- *
274
- * @param array $values Array of key value pairs which should be added to the Smart-Cookie cookie
275
- * @param int $expiration Number of seconds until the cookie will expire
276
- *
277
- * @return array Returns the whole updated cookie as array
278
- */
274
+ /**
275
+ * Sets values to the SmartCookie
276
+ *
277
+ * @param array $values Array of key value pairs which should be added to the Smart-Cookie cookie
278
+ * @param int $expiration Number of seconds until the cookie will expire
279
+ */
279
280
private function setCookieValues ( $ values , $ expiration = 7200 ) {
280
281
$ cookie = [];
281
282
if ( isset ( $ _COOKIE [ $ this ->cookie_key ] ) ) {
@@ -294,9 +295,6 @@ private function setCookieValues( $values, $expiration = 7200 ) {
294
295
$ cookie_encoded = json_encode ( $ cookie );
295
296
296
297
setcookie ( $ this ->cookie_key , $ cookie_encoded , time () + $ expiration , '/ ' , $ this ->cookie_domain );
297
-
298
- return false ;
299
-
300
298
}
301
299
302
300
/**
@@ -307,12 +305,12 @@ private function setCookieValues( $values, $expiration = 7200 ) {
307
305
public function renderSharePage ( $ debug = false ) {
308
306
if ( ! $ this ->mustache ) {
309
307
if ( ! defined ( 'SMART_LIB_PATH ' ) ) {
310
- define ( 'SMART_LIB_PATH ' , realpath ( dirname ( __FILE__ ) ) . '/.. ' );
308
+ define ( 'SMART_LIB_PATH ' , realpath (__DIR__ ) . '/.. ' );
311
309
}
312
310
// Initialize mustache
313
- $ loader = new \ Mustache_Loader_FilesystemLoader ( SMART_LIB_PATH . '/views ' );
314
- $ partials = new \ Mustache_Loader_FilesystemLoader ( SMART_LIB_PATH . '/views/partials ' );
315
- $ this ->mustache = new \ Mustache_Engine ( [
311
+ $ loader = new Mustache_Loader_FilesystemLoader ( SMART_LIB_PATH . '/views ' );
312
+ $ partials = new Mustache_Loader_FilesystemLoader ( SMART_LIB_PATH . '/views/partials ' );
313
+ $ this ->mustache = new Mustache_Engine ( [
316
314
'loader ' => $ loader ,
317
315
'partials_loader ' => $ partials ,
318
316
] );
@@ -323,7 +321,7 @@ public function renderSharePage( $debug = false ) {
323
321
$ meta = $ this ->getMeta ();
324
322
if ( isset ( $ meta ['image ' ] ) ) {
325
323
if ( extension_loaded ( 'gd ' ) && function_exists ( 'gd_info ' ) && $ meta ['image ' ] ) {
326
- list ( $ width , $ height ) = getimagesize ( $ meta ['image ' ] );
324
+ [ $ width , $ height ] = getimagesize ( $ meta ['image ' ] );
327
325
$ this ->meta ['image_height ' ] = $ height ;
328
326
$ this ->meta ['image_width ' ] = $ width ;
329
327
}
@@ -738,13 +736,12 @@ private function shortenLink( $url ) {
738
736
739
737
// Do something with the result. Here, we echo the long URL
740
738
$ data = json_decode ( $ data );
741
-
742
- $ this ->url_short_array [ $ url ] = $ data ->shorturl ;
739
+ $ this ->url_short_array [ $ url ] = isset ($ data ->shorturl )? $ data ->shorturl : $ url ;
743
740
744
741
$ value ->set ( $ this ->url_short_array );
745
742
$ cache ->save ( $ value );
746
743
747
- return $ data ->shorturl ;
744
+ return isset ( $ data ->shorturl )? $ data -> shorturl : $ url ;
748
745
}
749
746
750
747
/**
@@ -838,7 +835,7 @@ private function parse_signed_request( $signed_request ) {
838
835
}
839
836
840
837
//$signed_request = $_REQUEST['signed_request'];
841
- list ( $ encoded_sig , $ payload ) = explode ( '. ' , $ signed_request , 2 );
838
+ [ $ encoded_sig , $ payload ] = explode ( '. ' , $ signed_request , 2 );
842
839
$ data = json_decode ( base64_decode ( strtr ( $ payload , '-_ ' , '+/ ' ) ), true );
843
840
844
841
return $ data ;
0 commit comments